-@node Conditionals and Looping, Statistics, Data Selection, Top
+@node Conditionals and Looping
@chapter Conditional and Looping Constructs
@cindex conditionals
@cindex loops
* LOOP:: Repeat a block of code.
@end menu
-@node BREAK, DO IF, Conditionals and Looping, Conditionals and Looping
+@node BREAK
@section BREAK
@vindex BREAK
@cmd{BREAK} is allowed only inside @cmd{LOOP}@dots{}@cmd{END LOOP}.
@xref{LOOP}, for more details.
-@node DO IF, DO REPEAT, BREAK, Conditionals and Looping
+@node DO IF
@section DO IF
@vindex DO IF
(@pxref{TEMPORARY}), the @cmd{LAG} function may not be used
(@pxref{LAG}).
-@node DO REPEAT, LOOP, DO IF, Conditionals and Looping
+@node DO REPEAT
@section DO REPEAT
@vindex DO REPEAT
@display
-DO REPEAT repvar_name=expansion@dots{}.
+DO REPEAT dummy_name=expansion@dots{}.
@dots{}
END REPEAT [PRINT].
different variables, numbers, or strings into the block with each
repetition.
-Specify a repeat variable name followed by an equals sign (@samp{=}) and
+Specify a dummy variable name followed by an equals sign (@samp{=}) and
the list of replacements. Replacements can be a list of variables
-(which may be existing variables or new variables or a combination
-thereof), of numbers, or of strings. When new variable names are
+(which may be existing variables or new variables or some combination),
+numbers, or strings. When new variable names are
specified, @cmd{DO REPEAT} creates them as numeric variables. When numbers
-are specified, runs of integers may be indicated with TO notation, for
-instance @samp{1 TO 5} and @samp{1 2 3 4 5} would be equivalent. There
-is no equivalent notation for string values.
+are specified, runs of increasing integers may be indicated as
+@code{@var{num1} TO @var{num2}}, so that
+@samp{1 TO 5} is short for @samp{1 2 3 4 5}.
-Multiple repeat variables can be specified. When this is done, each
+Multiple dummy variables can be specified. Each
variable must have the same number of replacements.
The code within @cmd{DO REPEAT} is repeated as many times as there are
replacements for each variable. The first time, the first value for
-each repeat variable is substituted; the second time, the second value
-for each repeat variable is substituted; and so on.
+each dummy variable is substituted; the second time, the second value
+for each dummy variable is substituted; and so on.
-Repeat variable substitutions work like macros. They take place
-anywhere in a line that the repeat variable name occurs as a token,
-including command and subcommand names. For this reason it is not a
-good idea to select words commonly used in command and subcommand names
-as repeat variable identifiers.
+Dummy variable substitutions work like macros. They take place
+anywhere in a line that the dummy variable name occurs as a token,
+including command and subcommand names. For this reason,
+words commonly used in command and subcommand names should not be used
+as dummy variable identifiers.
If PRINT is specified on @cmd{END REPEAT}, the commands after substitutions
are made are printed to the listing file, prefixed by a plus sign
(@samp{+}).
-@node LOOP, , DO REPEAT, Conditionals and Looping
+@node LOOP
@section LOOP
@vindex LOOP
condition is false or missing before the loop contents are executed the
first time, the loop contents are not executed at all.
-If index and condition clauses are both present on @cmd{LOOP}, the index
-clause is always evaluated first.
+If index and condition clauses are both present on @cmd{LOOP}, the
+index variable is always set before the condition is evaluated. Thus,
+a condition that makes use of the index variable will always see the
+index value to be used in the next execution of the body.
Specify a boolean expression for the condition on @cmd{END LOOP} to cause
-the loop to terminate if the condition is not true after the enclosed
+the loop to terminate if the condition is true after the enclosed
code block is executed. The condition is evaluated at the end of the
-loop, not at the beginning.
+loop, not at the beginning, so that the body of a loop with only a
+condition on @cmd{END LOOP} will always execute at least once.
-If the index clause and both condition clauses are not present, then the
-loop is executed MXLOOPS (@pxref{SET}) times.
+If neither the index clause nor either condition clause is
+present, then the loop is executed MXLOOPS (@pxref{SET}) times.
@cmd{BREAK} also terminates @cmd{LOOP} execution (@pxref{BREAK}).