1
0
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:
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

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. 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