mirror of
https://github.com/vlang/v.git
synced 2025-09-14 23:12:33 +03:00
docs: add an example of variable swapping (#8306)
This commit is contained in:
parent
b04b8d438b
commit
ae1c7de604
1 changed files with 11 additions and 0 deletions
11
doc/docs.md
11
doc/docs.md
|
@ -326,6 +326,17 @@ fn main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The values of multiple variables can be changed in one line.
|
||||||
|
In this way, their values can be swapped without an intermediary variable.
|
||||||
|
|
||||||
|
```v
|
||||||
|
mut a := 0
|
||||||
|
mut b := 1
|
||||||
|
println('$a, $b') // 0, 1
|
||||||
|
a, b = b, a
|
||||||
|
println('$a, $b') // 1, 0
|
||||||
|
```
|
||||||
|
|
||||||
### Declaration errors
|
### Declaration errors
|
||||||
|
|
||||||
In development mode the compiler will warn you that you haven't used the variable
|
In development mode the compiler will warn you that you haven't used the variable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue