Difference between revisions of "FOR"

From Lianjapedia
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
[LOOP]
 
[LOOP]
  
NEXT
+
ENDFOR | NEXT
  
 
==See Also==
 
==See Also==
Line 17: Line 17:
  
 
==Description==
 
==Description==
The FOR ... NEXT command repeats the commands between the FOR and the NEXT statement.  The <exp1> specifies the loop start point and <exp2> the loop end point.  <exp1> and <exp2> may be integer or date values.  The FOR...NEXT command is equivalent to a counter based DO WHILE ... ENDDO set of commands but FOR ... NEXT is faster.
+
The FOR...ENDFOR | FOR...NEXT command repeats the commands between the FOR and the ENDFOR | NEXT statement.  The <exp1> specifies the loop start point and <exp2> the loop end point.  <exp1> and <exp2> may be integer or date values.  The FOR...ENDFOR | FOR...NEXT command is equivalent to a counter based DO WHILE...ENDDO set of commands but is faster.
  
 
====STEP <expN>====
 
====STEP <expN>====
If the optional STEP <expN1>, is specified, then the FOR ... NEXT loop will increment by <expN1>.  This value can be a positive or negative number.  If <expN1> is not specified then the FOR ... NEXT loop will increment by 1.
+
If the optional STEP <expN1>, is specified, then the loop will increment by <expN1>.  This value can be a positive or negative number.  If <expN1> is not specified then the loop will increment by 1.
  
 
====EXIT====
 
====EXIT====
Line 26: Line 26:
  
 
====LOOP====
 
====LOOP====
If a LOOP command is encountered, then control returns to the start of the FOR ... NEXT loop.
+
If a LOOP command is encountered, then control returns to the start of the loop.
  
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
 +
for i = 1 to 10 step 2
 +
    ?i*2
 +
endfor
 +
 
for i = 1 to 10 step 2
 
for i = 1 to 10 step 2
 
     ?i*2
 
     ?i*2
Line 35: Line 39:
 
</code>
 
</code>
  
==Products==
 
Lianja Server, Lianja
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Commands]]
 
[[Category:Commands]]
[[Category:Applications]]
 
[[Category:Applications Commands]]
 
 
[[Category:Looping Commands]]
 
[[Category:Looping Commands]]

Latest revision as of 08:30, 4 January 2021

Purpose

Processes a list of commands in a loop for a specified number of times

Syntax

FOR <memvar> = <exp1> TO <exp2>

[STEP <expN1>]

[EXIT]

[LOOP]

ENDFOR | NEXT

See Also

++, --, DO WHILE, FOREACH, SCAN

Description

The FOR...ENDFOR | FOR...NEXT command repeats the commands between the FOR and the ENDFOR | NEXT statement. The <exp1> specifies the loop start point and <exp2> the loop end point. <exp1> and <exp2> may be integer or date values. The FOR...ENDFOR | FOR...NEXT command is equivalent to a counter based DO WHILE...ENDDO set of commands but is faster.

STEP <expN>

If the optional STEP <expN1>, is specified, then the loop will increment by <expN1>. This value can be a positive or negative number. If <expN1> is not specified then the loop will increment by 1.

EXIT

The looping will continue until either <expN2> is reached or an EXIT command is encountered.

LOOP

If a LOOP command is encountered, then control returns to the start of the loop.

Example

for i = 1 to 10 step 2
    ?i*2
endfor
 
for i = 1 to 10 step 2
    ?i*2
next