while
statement
Syntax
WhileStatement :
while
Expression{
(Statement | Expression)+
}
A while
loop begins by evaluation the boolean loop conditional expression. If the loop conditional expression evaluates to true
, the loop body block executes, then control returns to the loop conditional expression. If the loop conditional expression evaluates to false
, the while
expression completes.
Example:
contract Foo {
pub fn bar() -> u256 {
let mut sum: u256 = 0
while sum < 10 {
sum += 1
}
return sum
}
}