mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
doc: explain labelled break and continue (#6890)
This commit is contained in:
parent
d5242e0bf5
commit
09090bd29f
24
doc/docs.md
24
doc/docs.md
@ -947,6 +947,30 @@ stuck in an infinite loop.
|
|||||||
|
|
||||||
Here `i` doesn't need to be declared with `mut` since it's always going to be mutable by definition.
|
Here `i` doesn't need to be declared with `mut` since it's always going to be mutable by definition.
|
||||||
|
|
||||||
|
#### Labelled break & continue
|
||||||
|
|
||||||
|
`break` and `continue` control the innermost `for` loop by default.
|
||||||
|
You can also use `break` and `continue` followed by a label name to refer to an outer `for`
|
||||||
|
loop:
|
||||||
|
|
||||||
|
```v
|
||||||
|
outer: for i := 4;; i++ {
|
||||||
|
println(i)
|
||||||
|
for {
|
||||||
|
if i < 7 {continue outer}
|
||||||
|
else {break outer}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
The label must immediately precede the outer loop.
|
||||||
|
The above code prints:
|
||||||
|
```
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
```
|
||||||
|
|
||||||
### Match
|
### Match
|
||||||
|
|
||||||
```v
|
```v
|
||||||
|
Loading…
Reference in New Issue
Block a user