Until
See Also: Boolean Expressions, Execution Control Commands, For, Loop, Repeat, While, Break, Boolean
Purpose
Establishes a conditional terminator for repeating blocks of code initiated with Repeat or While.
Syntax
repeat
... commands ...
until {expression}
What It Does
The until command sends execution back to the last previous repeat command until the test expression becomes true. When the test becomes true, execution proceeds to the command following the until command.
Procedure AddRecs
String sName sAddress sPhone
repeat
readln sName sAddress sPhone // will set SeqEof if end of file
If not (SeqEOF) ;
Send SaveNewRecord sName sAddress sPhone
until (SeqEOF)
End_Procedure
In this example, the loop keeps executing until the end of the sequential file is encountered. This represents normal usage of this command. SeqEOF is the sequential end of file indicator.
Procedure AddRecs
Integer iCount
String sName sAddress sPhone
move 0 to iCount
repeat
readln sName sAddress sPhone
Send SaveNewRecord sName sAddress sPhone
increment iCount
until (iCount > 100)
End_Procedure
In this example, the loop keeps executing until the variable iCount becomes greater than or equal to 100, at which point execution moves to the next statement (end_procedure).
A repeat ... until block will always execute at least once.
You may make until subject to "compound" conditionals.
Procedure AddRecs
Integer iCount
String sName sAddress sPhone
move 0 to iCount
repeat
readln sName sAddress sPhone
If not (SeqEOF) begin
Send SaveNewRecord sName sAddress sPhone
increment iCount
end
until (SeqEOF or (iCount > 100))
End_Procedure
SeqEOF is the sequential end of file indicator.
Notes
- The statements inside blocks are usually indented to make the blocks more readable.
- A variable or expression with a value of zero (0) is the test equivalent of false. A variable with a value other than zero is the test equivalent of true.
Untilcan also be used with statement blocks that were started withfororwhile, although such usage is considered to be unusual.