Another form of controlling the direction of a program would be loops. Loops are used to repeat a statement a specific number of times or until the condition is met. The next example shows a very simple while loop. The loop begins by prompting the user to input a starting number. The loop then compares the value of x with the conditional statement (x>0). While (x>0) the loop will continue and decrement the value of x each iteration.
Monday, February 9, 2009
Introduction to Programming :: Conditional Statements and Loops
Conditional Statements are used to control the direction of you program. There are many strategies for controlling you program. Most commonly used are if statements. An if statement pseudo code would be; if (a){instructions}. The (a) is the condition that has to be met in order for the {instructions} to proceed. Often there are times when you need to designate what will happen if the conditions are not met by using else.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment