Split pspp.texi into one texi file per chapter
[pspp-builds.git] / doc / flow-control.texi
diff --git a/doc/flow-control.texi b/doc/flow-control.texi
new file mode 100644 (file)
index 0000000..2145033
--- /dev/null
@@ -0,0 +1,164 @@
+@node Conditionals and Looping, Statistics, Data Selection, Top
+@chapter Conditional and Looping Constructs
+@cindex conditionals
+@cindex loops
+@cindex flow of control
+@cindex control flow
+
+This chapter documents PSPP commands used for conditional execution,
+looping, and flow of control.
+
+@menu
+* BREAK::                       Exit a loop.
+* DO IF::                       Conditionally execute a block of code.
+* DO REPEAT::                   Textually repeat a code block.
+* LOOP::                        Repeat a block of code.
+@end menu
+
+@node BREAK, DO IF, Conditionals and Looping, Conditionals and Looping
+@section BREAK
+@vindex BREAK
+
+@display
+BREAK.
+@end display
+
+@cmd{BREAK} terminates execution of the innermost currently executing
+@cmd{LOOP} construct.
+
+@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
+@section DO IF
+@vindex DO IF
+
+@display
+DO IF condition.
+        @dots{}
+[ELSE IF condition.
+        @dots{}
+]@dots{}
+[ELSE.
+        @dots{}]
+END IF.
+@end display
+
+@cmd{DO IF} allows one of several sets of transformations to be
+executed, depending on user-specified conditions.
+
+If the specified boolean expression evaluates as true, then the block
+of code following @cmd{DO IF} is executed.  If it evaluates as
+missing, then
+none of the code blocks is executed.  If it is false, then
+the boolean expression on the first @cmd{ELSE IF}, if present, is tested in
+turn, with the same rules applied.  If all expressions evaluate to
+false, then the @cmd{ELSE} code block is executed, if it is present.
+
+When @cmd{DO IF} or @cmd{ELSE IF} is specified following @cmd{TEMPORARY}
+(@pxref{TEMPORARY}), the @cmd{LAG} function may not be used
+(@pxref{LAG}).
+
+@node DO REPEAT, LOOP, DO IF, Conditionals and Looping
+@section DO REPEAT
+@vindex DO REPEAT
+
+@display
+DO REPEAT repvar_name=expansion@dots{}.
+        @dots{}
+END REPEAT [PRINT].
+
+expansion takes one of the following forms:
+        var_list
+        num_or_range@dots{}
+        'string'@dots{}
+
+num_or_range takes one of the following forms:
+        number
+        num1 TO num2
+@end display
+
+@cmd{DO REPEAT} repeats a block of code, textually substituting
+different variables, numbers, or strings into the block with each
+repetition.
+
+Specify a repeat 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
+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.
+
+Multiple repeat variables can be specified.  When this is done, 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.
+
+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.
+
+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
+@section LOOP
+@vindex LOOP
+
+@display
+LOOP [index_var=start TO end [BY incr]] [IF condition].
+        @dots{}
+END LOOP [IF condition].
+@end display
+
+@cmd{LOOP} iterates a group of commands.  A number of
+termination options are offered.
+
+Specify index_var to make that variable count from one value to
+another by a particular increment.  index_var must be a pre-existing
+numeric variable.  start, end, and incr are numeric expressions
+(@pxref{Expressions}.)  
+
+During the first iteration, index_var is set to the value of start.
+During each successive iteration, index_var is increased by the value of
+incr.  If end > start, then the loop terminates when index_var > end;
+otherwise it terminates when index_var < end.  If incr is not specified
+then it defaults to +1 or -1 as appropriate.
+
+If end > start and incr < 0, or if end < start and incr > 0, then the
+loop is never executed.  index_var is nevertheless set to the value of
+start.
+
+Modifying index_var within the loop is allowed, but it has no effect on
+the value of index_var in the next iteration.
+
+Specify a boolean expression for the condition on @cmd{LOOP} to
+cause the loop to be executed only if the condition is true.  If the
+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.
+
+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
+code block is executed.  The condition is evaluated at the end of the
+loop, not at the beginning.
+
+If the index clause and both condition clauses are not present, then the
+loop is executed MXLOOPS (@pxref{SET}) times.
+
+@cmd{BREAK} also terminates @cmd{LOOP} execution (@pxref{BREAK}).
+
+When @cmd{LOOP} or @cmd{END LOOP} is specified following @cmd{TEMPORARY}
+(@pxref{TEMPORARY}), the @cmd{LAG} function may not be used
+(@pxref{LAG}).
+@setfilename ignored