Loop: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(Created page with "The '''Loop''' statement works in conjunction with Do and Exit Do. DO/LOOP structure can be used to replace GOTO statements for more structured programming. N...")
 
 
(4 intermediate revisions by the same user not shown)
Line 3: Line 3:
DO/LOOP structure can be used to replace [[GOTO]] statements for more structured programming. Notably, [[labels]] or [[line numbers]] are not required to exit the loop.
DO/LOOP structure can be used to replace [[GOTO]] statements for more structured programming. Notably, [[labels]] or [[line numbers]] are not required to exit the loop.


The DO and LOOP statements must always be used in conjunction with one another to specify the beginning and ending of the loop. The Exit DO statement may be used to break out of the loop.
The [[DO LOOP|DO and LOOP]] statements must always be used in conjunction with one another to specify the beginning and ending of the loop. The Exit DO statement may be used to break out of the loop.


===Syntax===
===Syntax===
LOOP [{WHILE|UNTIL} <[[conditional expression]]>]
[[Image:Loop.png]]
[[Image:Loop.png]]


===Default===
===Default===
1.) When no WHILE or UNTIL condition is specified, continue executing the loop until the DO statement's conditions or an Exit DO indicate otherwise.
1.) When no [[WHILE]] or [[UNTIL]] condition is specified, continue executing the loop until the DO statement's conditions or an Exit DO indicate otherwise.


The WHILE keyword indicates that execution should return to the previous DO statement only if the specified conditional expression evaluates to true. If the conditional expression evaluates to false, execution will skip to the first line following the LOOP statement.
The WHILE keyword indicates that execution should return to the previous DO statement only if the specified conditional expression evaluates to true. If the conditional expression evaluates to false, execution will skip to the first line following the LOOP statement.
Line 18: Line 20:


See the [[DO LOOP]] and [[Exit Do]] statements in this section for additional information about the DO/LOOP structure.
See the [[DO LOOP]] and [[Exit Do]] statements in this section for additional information about the DO/LOOP structure.
===Examples===
The following code uses a DO LOOP combination to allow a [[Check Box]] GUI to work:
00350    do
00360        input fields "22,14,CHECK 8,,10;23,14,CHECK 8,,11;24,14,CHECK 8,,12": Box$(1),Box$(2),Box$(3)
00370        print fields "24,1,N 2": Fkey
00380    loop While Fkey~=99
In this case, pressing ESC will set the Fkey equal to 99 and exit the loop.


<noinclude>
<noinclude>

Latest revision as of 15:34, 5 May 2014

The Loop statement works in conjunction with Do and Exit Do.

DO/LOOP structure can be used to replace GOTO statements for more structured programming. Notably, labels or line numbers are not required to exit the loop.

The DO and LOOP statements must always be used in conjunction with one another to specify the beginning and ending of the loop. The Exit DO statement may be used to break out of the loop.

Syntax

LOOP [{WHILE|UNTIL} <conditional expression>]

Default

1.) When no WHILE or UNTIL condition is specified, continue executing the loop until the DO statement's conditions or an Exit DO indicate otherwise.

The WHILE keyword indicates that execution should return to the previous DO statement only if the specified conditional expression evaluates to true. If the conditional expression evaluates to false, execution will skip to the first line following the LOOP statement.

The UNTIL keyword indicates that execution should return to the previous DO statement only if the specified conditional expression evaluates to false. If the conditional expression evaluates to true, execution will skip to the first line following the LOOP statement.

The LOOP statement must be the last statement in a line, and the LOOP keyword is always required. CONFIG STYLE INDENT will cause lines between the DO and LOOP statements to be indented.

See the DO LOOP and Exit Do statements in this section for additional information about the DO/LOOP structure.

Examples

The following code uses a DO LOOP combination to allow a Check Box GUI to work:

00350     do
00360        input fields "22,14,CHECK 8,,10;23,14,CHECK 8,,11;24,14,CHECK 8,,12": Box$(1),Box$(2),Box$(3)
00370        print fields "24,1,N 2": Fkey
00380     loop While Fkey~=99

In this case, pressing ESC will set the Fkey equal to 99 and exit the loop.