From b2f7b3b79f3117885b265575f6c5dbf934757797 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 21 Dec 2022 12:04:59 -0300 Subject: Control variables in for loops are read only --- manual/manual.of | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'manual') diff --git a/manual/manual.of b/manual/manual.of index 416622c1..73d25951 100644 --- a/manual/manual.of +++ b/manual/manual.of @@ -1467,7 +1467,7 @@ It has the following syntax: exp @bnfter{,} exp @bnfopt{@bnfter{,} exp} @Rw{do} block @Rw{end}} } The given identifier (@bnfNter{Name}) defines the control variable, -which is a new variable local to the loop body (@emph{block}). +which is a new read-only variable local to the loop body (@emph{block}). The loop starts by evaluating once the three control expressions. Their values are called respectively @@ -1499,11 +1499,6 @@ For integer loops, the control variable never wraps around; instead, the loop ends in case of an overflow. -You should not change the value of the control variable -during the loop. -If you need its value after the loop, -assign it to another variable before exiting the loop. - } @sect4{@title{The generic @Rw{for} loop} @@ -1526,7 +1521,8 @@ for @rep{var_1}, @Cdots, @rep{var_n} in @rep{explist} do @rep{body} end works as follows. The names @rep{var_i} declare loop variables local to the loop body. -The first of these variables is the @emph{control variable}. +The first of these variables is the @emph{control variable}, +which is a read-only variable. The loop starts by evaluating @rep{explist} to produce four values: @@ -1550,9 +1546,6 @@ to-be-closed variable @see{to-be-closed}, which can be used to release resources when the loop ends. Otherwise, it does not interfere with the loop. -You should not change the value of the control variable -during the loop. - } } @@ -9156,6 +9149,9 @@ change between versions. @itemize{ @item{ +The control variable in @Rw{for} loops are read only. +If you need to change it, +declare a local variable with the same name in the loop body. } } -- cgit v1.2.3-55-g6feb