Difference between revisions of "Do"
From Hercules Wiki
Dastgirpojee (Talk | contribs) m |
(nevermind me [2]) |
||
(One intermediate revision by one user not shown) | |||
Line 8: | Line 8: | ||
repeated. When the condition is false, control is transferred to the | repeated. When the condition is false, control is transferred to the | ||
statement following the '[[do]]...[[while]]' loop expression. | statement following the '[[do]]...[[while]]' loop expression. | ||
+ | |||
<pre>do { | <pre>do { | ||
Line 28: | Line 29: | ||
} while (.@i > 0); | } while (.@i > 0); | ||
</pre> | </pre> | ||
+ | |||
[[Category:Script Command]] | [[Category:Script Command]] |
Latest revision as of 13:53, 17 January 2015
Syntax
- do { <statement>; } while (<condition>);
Description
The 'do...while' is the only post-test loop structure available in this script language. With a post-test, the statements are executed once before the condition is tested. When the condition is true, the statement(s) are repeated. When the condition is false, control is transferred to the statement following the 'do...while' loop expression.
do { Code to execute(1) } while (expression(2));
Example 1: sentinel-controlled loop mes "This menu will keep appearing until you pick Cancel"; do { set .@menu, select("One:Two:Three:Cancel"); } while (.@menu != 4);
Example 2: counter-controlled loop mes "This will countdown from 10 to 1."; set .@i, 10; do { mes .@i; set .@i, .@i - 1; } while (.@i > 0);