Difference between revisions of "The Script Programming Language/Control Flow"
(Created page with "==<br /> Control Flow == In the following, code1, ..., codeN are arbitrary sequences of expressions. There are no BEGIN ... END blocks as in Pascal or progn forms as in Lisp....") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[The Original SCI Documentation]]<br /> | ||
+ | |||
+ | <div align="center"> | ||
+ | Chapter: | ||
+ | [[The Script Programming Language/Introduction|1]] | | ||
+ | [[The Script Programming Language/Files|2]] | | ||
+ | [[The Script Programming Language/Definitions|3]] | | ||
+ | [[The Script Programming Language/Data Types and Variables|4]] | | ||
+ | [[The Script Programming Language/Primitive Procedures|5]] | | ||
+ | [[The Script Programming Language/Control Flow|6]] | | ||
+ | [[The Script Programming Language/Procedures|7]] | | ||
+ | [[The Script Programming Language/Using SC|8]] | | ||
+ | [[The Script Programming Language/Index|Index]] | ||
+ | </div><br /> | ||
+ | |||
+ | <div align="center"><span style="font-size: 22pt">The Script Programming Language</span><br /> | ||
+ | <span style="font-size: 22pt">Control Flow</span><br /> | ||
+ | ''Author: [[Jeff Stephenson]]''</div> | ||
+ | |||
+ | | ||
+ | |||
==<br /> Control Flow == | ==<br /> Control Flow == | ||
Line 150: | Line 171: | ||
If expression is not FALSE, loop back to the beginning of the nth level loop. If n is not specified, loop to the beginning of the innermost loop. | If expression is not FALSE, loop back to the beginning of the nth level loop. If n is not specified, loop to the beginning of the innermost loop. | ||
+ | |||
+ | | ||
+ | |||
+ | ;Notes | ||
+ | <references /> | ||
+ | |||
+ | | ||
+ | |||
+ | [[The Script Programming Language | Table of Contents]] | ||
+ | |||
+ | <span style="float: left">[[The Script Programming Language/Primitive Procedures | < Previous: Primitive Procedures]]</span><span style="float: right">[[The Script Programming Language/Procedures | Next: Procedures >]]</span> | ||
+ | |||
+ | | ||
+ | |||
+ | [[Category:SCI Documentation]] | ||
+ | [[Category:Scripting]] | ||
+ | [[Category:Control Flow]] | ||
+ | [[Category:Conditionals]] | ||
+ | [[Category:Iteration]] |
Latest revision as of 20:14, 2 December 2015
The Original SCI Documentation
Control Flow
In the following, code1, ..., codeN are arbitrary sequences of expressions. There are no BEGIN ... END blocks as in Pascal or progn forms as in Lisp.
The value of a control flow expression is the value of the last expression in the control body which was evaluated. Thus, if we execute the following code:
Code:(= x 3) (= y 2) (= y (if (> x y) (- x y) else (+ x y) ) )
y will have the value 1.
Return:
Code:(return [expression])
The return statement returns control to the procedure which called the currently executing procedure. If the optional expression is present, that value is returned as the value of the current procedure. There is an implicit return at the end of all procedures, and the value returned in that case is the value of the last expression evaluated. A return from the main procedure of script 0 returns to the operating system.
Conditionals:
Code:(if expression code1 [else code2])
If expression is not FALSE, execute code1, else execute code2. (The else clause is optional).
Code:(cond (e1 code1) (e2 code2) ... [(else codeN)])
Evaluate e1. If it is not FALSE, execute code1 and exit the cond clause. If it is FALSE, evaluate e2 and continue. If all of the expressions are FALSE and the optional else clause is present, execute codeN.
Code:(switch expression (exp1 code1) (exp2 code2) ... [(else codeN)])
Evaluate expression. If it is equal to exp1, execute code1 and exit the switch. If it is equal to exp2, execute code2 and exit. If it doesn't equal any of the expressions and the optional else clause is present, execute codeN.
Iteration:
Code:(for (initialization) condition (re-initialization) code)
Evaluate the expressions comprising initialization. Then evaluate condition. If the result is FALSE, exit the loop. Otherwise, execute code, then the expressions comprising re-initialization, and loop back to condition.
Code:(while condition code)
Evaluate condition. If not FALSE, execute code and loop back to evaluate condition again. Exit the loop when condition is FALSE. (Note that this means that the value of a while condition is always FALSE.) This is equivalent to
Code:(for () condition () code)
Code:(repeat code)
Continually execute the code until some condition in the code (a break) causes the loop to be exited. This is equivalent to
Code:(while TRUE code)
or
Code:(for () TRUE () code)
Supporting constructs for iteration:
Code:(break [n])
Break out of n levels of loops. If n is not specified break out of the innermost loop.
Code:(breakif expression [n])
If expression is not FALSE, break out of n levels of loops. If n is not specified, break out of the innermost loop.
Code:(continue [n])
Loop back to the beginning of the nth level loop. If n is not specified, loop to the beginning of the innermost loop.
Code:(contif expression [n])
If expression is not FALSE, loop back to the beginning of the nth level loop. If n is not specified, loop to the beginning of the innermost loop.
- Notes
< Previous: Primitive Procedures Next: Procedures >