Skip to content

Commit b39ffe7

Browse files
committed
spec: cover continue statement
1 parent 38b88a5 commit b39ffe7

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* [`for` Statement](spec/statement_for.md)
3636
* [`while` Statement](spec/statement_while.md)
3737
* [`break` Statement](spec/statement_break.md)
38+
* [`continue` Statement](spec/statement_continue.md)
3839
* [Expressions](spec/expressions.md)
3940
* [Literal expressions](spec/expr-literal.md)
4041
* [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
@@ -29,6 +29,7 @@
2929
* [`for` Statement](statement_for.md)
3030
* [`while` Statement](statement_while.md)
3131
* [`break` Statement](statement_break.md)
32+
* [`continue` Statement](statement_continue.md)
3233
* [Expressions](expressions.md)
3334
* [Literal expressions](expr-literal.md)
3435
* [Arithmetic Operators](arithmetic_operators.md)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# `continue` statement
2+
3+
4+
> **<sup>Syntax</sup>**\
5+
> _ContinueStatement_ :\
6+
> &nbsp;&nbsp; `continue`
7+
8+
The `continue` statement can only be used within a [`for`] or [`while`] loop and causes the immediate termination of the current iteration, returning control to the loop head.
9+
10+
If used within nested loops the `continue` statement is associated with the innermost enclosing loop.
11+
12+
An example of a `continue` statement used within a [`while`] loop.
13+
14+
```python
15+
contract Foo:
16+
17+
pub fn bar() -> u256:
18+
let sum: u256
19+
while sum < 10:
20+
sum += 1
21+
22+
if self.some_skip_condition():
23+
continue
24+
25+
return sum
26+
27+
fn some_skip_condition -> bool:
28+
# some complex logic
29+
return true
30+
```
31+
32+
An example of a `continue` statement used within a [`for`] loop.
33+
34+
```python
35+
contract Foo:
36+
37+
pub fn bar(values: u256[10]) -> u256:
38+
let sum: u256
39+
for i in values:
40+
sum = sum + i
41+
42+
if self.some_skip_condition():
43+
continue
44+
45+
return sum
46+
47+
fn some_skip_condition -> bool:
48+
# some complex logic
49+
return true
50+
```
51+
52+
[`for`]: statement_for.md
53+
[`while`]: statement_while.md

0 commit comments

Comments
 (0)