!while(4)!while, !repeat, !break, !continue, !done, !until - loop
< !while condition | !repeat >
The six loop directives can be mixed and matched as required, a loop must have one of the start loop directive and an end loop directive; it can optionally have as many !break and !continue directives as needed.
The !repeat directive always executes the loop contents; whereas the !while directive allows statements within the loop to be executed only if the given condition is TRUE, if the condition is FALSE then execution is continued on the line after the loop end statement (!done or !until).
The !done directive always returns control back to the loop start directive (!while or !repeat statement), whereas !until only loops back to the start if the given condition is FALSE, exiting the loop otherwise.
A !continue may be used in the loop, this immediately returns control to the loop start line (!while or !repeat statement), skipping the rest of the loop content and end statement (including any !until condition). A !break can be used to exit a loop, execution resumes on the line after the end loop statement.
Up to six loops can be nested within a single function/executed buffer at any one time. If more are required then a sub function could be defined and called or the !goto(4) and !jump(4) directives could be used in conjunction with the !if(4) statement to construct loops.
For example, the following macro segment fills to the fill column with spaces.
!while &less $curcol $buffer-fill-col insert-string " " !if &equal %example "1" ; Silly to show continue !continue ; Goto !while !elif &equal %example "2" ; Silly to show continue !break ; Goto line after !done !endif ml-write "You wont see me if %example = 1 or 2" !done ml-write "LoopA has exited" set-variable #l1 10 !repeat 10 ml-write &spr "LoopB: %d" #l1 !until &les &dec #l1 1 1 100 ml-write &spr "LoopB end: #l1 should = 0 : %d" #l1 set-variable #l1 10 !repeat 10 ml-write &spr "LoopC: %d" #l1 !iif &les &dec #l1 1 1 !break !done 100 ml-write &spr "LoopC end: #l1 should = 0 : %d" #l1
(c) Copyright JASSPA 2025
Last Modified: 2022/06/12
Generated On: 2025/09/29