From 5ddb2d5b181f5e567d6c49860e9c4f37ec613e4f Mon Sep 17 00:00:00 2001 From: Subhomoy Haldar Date: Thu, 11 Mar 2021 18:23:58 +0530 Subject: [PATCH] docs: add a mutable iteration example (#9244) --- doc/docs.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index d4df490b21..4ad0a0e3cb 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1147,12 +1147,12 @@ The `for value in arr` form is used for going through elements of an array. If an index is required, an alternative form `for index, value in arr` can be used. Note, that the value is read-only. -If you need to modify the array while looping, you have to use indexing: +If you need to modify the array while looping, you need to declare the element as mutable: ```v mut numbers := [0, 1, 2] -for i, _ in numbers { - numbers[i]++ +for mut num in numbers { + num++ } println(numbers) // [1, 2, 3] ```