BYU Home pageBRIGHAM YOUNG UNIVERSITY
  Humanities Technology and Research Support Center
Back     CHum Revolution Gateway

CHum 210
Basic Control Structures

Objectives

By the end of this reading you should be able to answer the following questions:

  1. What are the three concepts fundamental to programming, regardless of the language?
  2. Understand when each of these concepts might apply when writing a program.
  3. Name two strategies that can be helpful in planning your program.

Basic Programming Concepts

Even though each programming language you use is unique, there are certain concepts common to all languages, including Revolution's scripting language. Let's look at some of the most common control structures used in programming.

Sequential commands (The right commands in the right order.)
Example: You want to clear your screen of all buttons and fields, show a field with text, wait for the user to click, then hide the field and show the former ones.
To work correctly, not only do all the commands have to be there, they have to be in the right order.

Conditional structures (Do certain things based on a true or false, yes or no decision.)
These provide for one command or sequence of commands to be executed if a statement is true; another command or sequence of commands if the statement is false.
Typically in the form if . . . then . . . else

Example 1: If a word exists in a list, then print it out,
Else tell the user that the word does not exist.

Example 2: If a sentence contains the word "silly" put that sentence into the silly list. If it doesn't contain the word "silly", put it into the serious list.

Looping structures (A list of instructions to do more than once.)
Used to make the computer repeat a certain command or sequence of commands. The loop may run for a predetermined number of times, until a certain condition becomes true, or as long as a certain condition remains true.

Here are some ways that looping might be done:
Do the following 20 times.
Do the following once for each word in the list
Repeat the following until the user presses the option key
Repeat the following as long as the option key is depressed.

Example: Given a list of party guests, assign everyone to one of three groups for "ice-breaker" games.

Programming Strategies

Programming can range in complexity from solving small problems (like setting an alarm time on your watch or cell phone) to very sophisticated instructional or business applications. For more complex tasks, you can use these strategies to help you think through the logic of your program before starting to write code.

Top-down design
Determine the main steps that needed to accomplish your task. Use flowchart, statements, etc. to represent the logical flow of your program.

Pseudocode
You use your knowledge of the basic control structures, common sense and logic to write plain-English statements of how you will accomplish each step.


Here is an exercise that can help you to clarify the role of control structures in programming.

Go to Structures In-class Exercise


Back     CHum Revolution Gateway
Maintained by Devin Asay.
Copyright © 2005 Brigham Young University