Skip to content

Commit 4bb4507

Browse files
committed
spec: cover while statement
1 parent 6dbc788 commit 4bb4507

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* [`return` Statement](spec/statement_return.md)
3434
* [`if` Statement](spec/statement_if.md)
3535
* [`for` Statement](spec/statement_for.md)
36+
* [`while` Statement](spec/statement_while.md)
3637
* [Expressions](spec/expressions.md)
3738
* [Literal expressions](spec/expr-literal.md)
3839
* [Arithmetic Operators](spec/arithmetic_operators.md)

docs/src/spec/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* [`return` Statement](statement_return.md)
2828
* [`if` Statement](statement_if.md)
2929
* [`for` Statement](statement_for.md)
30+
* [`while` Statement](statement_while.md)
3031
* [Expressions](expressions.md)
3132
* [Literal expressions](expr-literal.md)
3233
* [Arithmetic Operators](arithmetic_operators.md)

docs/src/spec/statement_while.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# `while` statement
2+
3+
4+
> **<sup>Syntax</sup>**\
5+
> _WhileStatement_ :\
6+
> &nbsp;&nbsp; `while` [_Expression_] `:` [NEWLINE]\
7+
> &nbsp;&nbsp; [INDENT]\
8+
> &nbsp;&nbsp; ([_Statement_] | [_Expression_])<sup>+</sup>\
9+
> &nbsp;&nbsp; [DEDENT]\
10+
11+
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.
12+
13+
Example:
14+
15+
```python
16+
contract Foo:
17+
18+
pub fn bar() -> u256:
19+
let sum: u256
20+
while sum < 10:
21+
sum += 1
22+
23+
return sum
24+
```
25+
26+
[NEWLINE]: tokens.md#newline
27+
[INDENT]: tokens.md#indent
28+
[DEDENT]: tokens.md#dedent
29+
[_Expression_]: expressions.md
30+
[_Statement_]: statements.md
31+
[boolean]: boolean_type.md

0 commit comments

Comments
 (0)