Difference between revisions of "Recital Flow Control and Looping"

From Recital Documentation Wiki
Jump to: navigation, search
(The Recital if Statement)
Line 1: Line 1:
 
==Recital Flow Control and Looping==
 
==Recital Flow Control and Looping==
 
===Recital Conditional Statements===
 
===Recital Conditional Statements===
===The Recital if Statement===
+
===Recital do...case statements===
 
+
The do...case command selects one course of action out of one or more alternatives.
 +
 
<pre>
 
<pre>
IF <condition>
+
do case
 +
case <condition as logical>
 +
[<commands>]
 +
[case <condition as logical>
 +
[<commands>]]
 +
[otherwise
 +
[<commands>]]
 +
endcase
 +
</pre>
  
[ELSEIF<condition>]
+
Each ''case condition'' is evaluated in turn.  As soon as one of the conditions evaluates to true (.T.) the ''commands'' for that case are executed and any further case statements are ignored.  Following execution of the ''commands'', the program continues after the ''endcase'' statement.  If an ''otherwise'' statement is present and no ''case condition'' evaluates to .T., the ''otherwise commands'' are executed.
  
[ELSE]
+
If no ''case condition'' evaluates to .T., and there is no ''otherwise'' statement specified, then control skips to the next command following the ''endcase''.
  
ENDIF
+
===The Recital if Statement===
 +
The IF command provides a conditional selection of commands to execute based upon a logical <condition>.  If the result of the <condition> is .T., then the commands following the IF, up to an ENDIF statement or an ELSE statement are executed. IF statements may be nested, i.e. IF statements may contain other IF statements, provided that the ELSE and ENDIF statements correspond with a valid IF.
 +
[edit]
 +
ELSEIF
 +
 
 +
The ELSEIF clause can be added to the IF control structure allowing for the testing of more than one condition in the IF...ENDIF block. The IF block is now essentially the same as the DO CASE structure. ELSEIF is analogous with the CASE statement.
 +
[edit]
 +
ELSE
 +
 
 +
The ELSE statement is analogous with the OTHERWISE statement. If no previous IF <condition> or ELSEIF <condition> is true, the commands following the ELSE statement up to the ENDIF statement are executed.
 +
 
 +
<pre>
 +
if <condition as logical>
 +
[elseif <condition as logical>]
 +
[else]
 +
endif
 
</pre>
 
</pre>
  
===The Recital if...else Statement===
+
 
 
===Recital Looping Statements===
 
===Recital Looping Statements===
 
===Recital for loops===
 
===Recital for loops===
 
===Recital do...while loops===
 
===Recital do...while loops===
===Recital do...case statements===
 
 
===Recital foreach loops===
 
===Recital foreach loops===
 
===Breaking a Loop===
 
===Breaking a Loop===
 
===Skipping Statements in a  Loop===
 
===Skipping Statements in a  Loop===
 
===Summary===
 
===Summary===

Revision as of 14:14, 14 January 2010

Recital Flow Control and Looping

Recital Conditional Statements

Recital do...case statements

The do...case command selects one course of action out of one or more alternatives.

do case
case <condition as logical>
[<commands>]
[case <condition as logical>
[<commands>]]
[otherwise
[<commands>]]
endcase 

Each case condition is evaluated in turn. As soon as one of the conditions evaluates to true (.T.) the commands for that case are executed and any further case statements are ignored. Following execution of the commands, the program continues after the endcase statement. If an otherwise statement is present and no case condition evaluates to .T., the otherwise commands are executed.

If no case condition evaluates to .T., and there is no otherwise statement specified, then control skips to the next command following the endcase.

The Recital if Statement

The IF command provides a conditional selection of commands to execute based upon a logical <condition>. If the result of the <condition> is .T., then the commands following the IF, up to an ENDIF statement or an ELSE statement are executed. IF statements may be nested, i.e. IF statements may contain other IF statements, provided that the ELSE and ENDIF statements correspond with a valid IF. [edit] ELSEIF

The ELSEIF clause can be added to the IF control structure allowing for the testing of more than one condition in the IF...ENDIF block. The IF block is now essentially the same as the DO CASE structure. ELSEIF is analogous with the CASE statement. [edit] ELSE

The ELSE statement is analogous with the OTHERWISE statement. If no previous IF <condition> or ELSEIF <condition> is true, the commands following the ELSE statement up to the ENDIF statement are executed.

if <condition as logical>
[elseif <condition as logical>]
[else]
endif


Recital Looping Statements

Recital for loops

Recital do...while loops

Recital foreach loops

Breaking a Loop

Skipping Statements in a Loop

Summary