doc: explain labelled break and continue (#6890)

pull/6892/head
Nick Treleaven 2020-11-20 13:11:56 +00:00 committed by GitHub
parent d5242e0bf5
commit 09090bd29f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -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.
#### 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
```v