Join the Discussion
There are two types of branching statements. The if statement is used for conditional execution of a single statement or to select which of two statements is to be executed. The case statement (sometimes referred to as the select statement) allows for selection of one statement out of three or more that should be executed.
Statements can be executed conditionally by using an if statement. The if statement specifies a condition which gets tested when the if statement is executed. If the condition is true then the following statement is executed otherwise processing skips that statement.
Optionally a second statement can be attached to the if statement that will be executed if the condition is false.
if x > y
print "x is bigger than y"
print "x is not bigger than y"
A case or select statement allows for one of a number of statements to be executed depending on the value of a field. There is usually also an additional statement which is executed if none of the specified values is matched.
1: print "small"
2: print "medium"
3: print "large"
otherwise: print "unknown"
The final structure type we can use with structured programming is looping.
Note that this article is copied from the "Ask Felgall" website with the permission of the copyright owner.