From ae1c7de604e90e8dc8f94889e10224c8de706e9b Mon Sep 17 00:00:00 2001 From: William Gooch Date: Sat, 23 Jan 2021 17:41:47 -0500 Subject: [PATCH] docs: add an example of variable swapping (#8306) --- doc/docs.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index b06597b989..ef88fb6cfd 100644 --- a/doc/docs.md +++ b/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 In development mode the compiler will warn you that you haven't used the variable