A while loop uses the while keyword followed by a condition which evaluates to a Boolean.
{{#include ../../../../code/language/control_flow/src/lib.sw:single_loop}}In the example above we use two conditions.
- If the
counteris less than10then continue to iterate - If the
conditionvariable istruethen continue to iterate
As long as both those conditions are true then the loop will iterate. In this case the loop will finish iterating once counter reaches the value of 6 because condition will be set to false.
Sway also allows nested while loops.
{{#include ../../../../code/language/control_flow/src/lib.sw:nested_loop}}