The If Statement
if statements are used for conditional branching.
if x > y then
The Case Statement
The case statement can test a variable for several different values.
type country is ( australia, u_k, brazil );
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 Statement
The 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
The For Loop Statement
The 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
To loop through values in the reverse order, use "in reverse" instead of "in".
The Exit Statement
Any loop can be exited by using either an exit statement or an "exit when" shorthand.
if x > 100 then
exit when x > 100;
The Loop Loop Statement
A "loop" loop is a general purpose loop. It can only be exited with "exit".
|Back To Top|