diff options
author | Robert Griesemer <gri@golang.org> | 2014-09-25 12:52:05 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2014-09-25 12:52:05 -0700 |
commit | ebbf1936a168a8a19f90a98767f10b78590e3cbf (patch) | |
tree | 0ff200bf3a0f21a1c97e305621b5264b54dca264 /doc | |
parent | 59ab5d9895fb06611f705763b127ae2982ce258f (diff) | |
download | go-ebbf1936a168a8a19f90a98767f10b78590e3cbf.tar.gz |
spec: clarify scope and re-use of iteration variables
Fixes issue 7834.
LGTM=iant, rsc, r
R=r, rsc, iant, ken
CC=golang-codereviews
https://codereview.appspot.com/148940044
Diffstat (limited to 'doc')
-rw-r--r-- | doc/go_spec.html | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index e0ed7e7b7..583517269 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -4682,6 +4682,7 @@ additionally it may specify an <i>init</i> and a <i>post</i> statement, such as an assignment, an increment or decrement statement. The init statement may be a <a href="#Short_variable_declarations">short variable declaration</a>, but the post statement must not. +Variables declared by the init statement are re-used in each iteration. </p> <pre class="ebnf"> @@ -4808,7 +4809,7 @@ The iteration variables may be declared by the "range" clause using a form of <a href="#Short_variable_declarations">short variable declaration</a> (<code>:=</code>). In this case their types are set to the types of the respective iteration values -and their <a href="#Declarations_and_scope">scope</a> ends at the end of the "for" +and their <a href="#Declarations_and_scope">scope</a> is the block of the "for" statement; they are re-used in each iteration. If the iteration variables are declared outside the "for" statement, after execution their values will be those of the last iteration. |