whileLoop
Description
Loop runs, and it continues to repeat as long as the condition remains true, it evaluates the condition first before looping.
Input / Parameter
condition
The condition to evaluates first before loop
boolean
-
-
Yes
Output
N/A
Callback
yesCallback
This will be triggered for every loop that happens while the condition remains true.
Example
In this example, we will do console logging by using console function in whileLoop callback
Code Equivalent
let n = 0;
while (n < 5) {
n++;
console.log("while loop"+n);
}Steps
Drag a
buttoncomponent into the canvas and open theActiontab. Select thepressevent of the button and drag thesetVarfunction to the event flow, add the valuenonvarparam and add the value0onvalueparam.
Drag the function
whileLoopto the eventflow, on it'sconditionparam change the param type to function/subflow then add functionlessinside the subflow, for thevalue1param change the param type to function/subflow then add functiongetVarinside the subflow, for thevarparam add valuen.
Drag the function
setVarinside functionwhileLoopyes callback, add valuenon paramvarand change the param type to subflow/function on paramvalue. Inside paramvaluesubflow addaddfunction then on it'svalue1change the param type to subflow/function, addgetVarfunction in it, then putnon it'svarparam value.
Drag the function
consoleinside functionwhileLoopyes callback, change the param type to subflow/function on paramvalue. Inside paramvaluesubflow addplusfunction then on it'svalue1param addwhile loopvalue, as forvalue2param change the param type to subflow/function, addgetVarfunction in it, then putnon it'svarparam value.
Result
Now click the button in preview, it will show the list of
while loopwith the current loop number on the console.
Links
Related Information
See also:
Functions
Last updated