Difference between revisions of "while"

From Bohemia Interactive Community
Jump to navigation Jump to search
m (<code> tidy + linking _x)
Line 17: Line 17:
 
____________________________________________________________________________________________
 
____________________________________________________________________________________________
 
   
 
   
|x1= <code>[[while]] {a<b} '''[[do]]''' {a<nowiki>=</nowiki>a+1} </code>
+
|x1= <code>[[while]] { a < b } '''[[do]]''' { a = a + 1 };</code>
|x2=A practical example: Repair all members of a group to such a level that they are able to stand up: <code><nowiki>{</nowiki><br>&nbsp;&nbsp;[[while]] <nowiki>{</nowiki>([[not]] [[canStand]] _x) [[and]] ([[alive]] _x)<nowiki>}</nowiki> [[do]] <nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;_x [[setDammage]] ([[getDammage]] _x) - 0.01;<br>&nbsp;&nbsp;<nowiki>};</nowiki><br><nowiki>}</nowiki> [[forEach]] [[units]] [[group]] unitname; </code> |= Example 2____________________________________________________________
+
|x2= A practical example: Repair all members of a group to such a level that they are able to stand up: <code>{
 +
    [[while]] { ([[not]] [[canStand]] [[Magic Variables|_x]]) [[and]] ([[alive]] [[Magic Variables|_x]]) } [[do]] {
 +
        [[Magic Variables|_x]] [[setDammage]] ([[getDammage]] [[Magic Variables|_x]]) - 0.01;
 +
    };
 +
} [[forEach]] [[units]] [[group]] unitname;</code> |= Example 2
 +
____________________________________________________________
  
 
| [[Control Structures]], [[waitUntil]] |= See also
 
| [[Control Structures]], [[waitUntil]] |= See also

Revision as of 18:42, 29 March 2014

Template:Command

Notes

Posted on May 14, 2008
Kronzky
The boolean code that's used to evaluate the while condition can be preceded by code that executes a regular command.
e.g. while {_a=_a+1; _a<10} do {...}
Posted on January 2, 2012
Lucky44
Different than in IF statements, the condition in a WHILE loop can use curly braces not parentheses, unless it has multiple conditions, as shown above. So this will be a problem: while (variable1 == "wait") do... But this will work: while {variable1 == "wait"} do...

Bottom Section