![]() | ![]() | |||||||||||||||
|
Flow of ControlThe If Statementif statements are used for conditional branching.
if x > y then
Example: The If Statement
The Case StatementThe case statement can test a variable for several different values.
type country is ( australia, u_k, brazil );
Example: The Case Statement
Multiple cases can be strung together using a vertical bar (|). when brazil | u_k => -- brazil or U.K. The "when" cases must not be variables (although constants are OK). The "when others" case is always required. You can create a do nothing case by using the null statement. Ada: The when others clause is optional in Ada. It's required in SparForte. The While Loop StatementThe while loop is a pre-test loop. The commands in the loop are repeat while the condition is true and the condition is tested each time the first line of the loop is executed.
while x < y loop
Example: The While Statement
The For Loop StatementThe for loop increments its index variable by 1 until it iterates through the specified range. The range can either be numeric or enumerated. The index identifier is automatically declared for you and only exists for the scope of the the loop. The index identifier is declared as a constant: you cannot assign a new value to it inside of the loop. (However, it can be changed at a breakout prompt for debugging purposes.)
for i in 1..10 loop
Example: The For Statement
To loop through values in the reverse order, use "in reverse" instead of "in". The Exit StatementAny loop can be exited by using either an exit statement or an "exit when" shorthand.
if x > 100 then exit when x > 100;
Example: Examples of the Exit Statement
The Loop Loop StatementA "loop" loop is a general purpose loop. It can only be exited with "exit".
loop
Example: The Loop Statement
|
![]() Block Statements and Subprograms |
![]() |
![]() |