<div dir="ltr">Hi Paul,<div><br></div><div>Thanks alot for your time and appreciate the detailed explanation.</div><div><br></div><div>Regards,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 15, 2023 at 2:21 AM Paul Reed <<a href="mailto:paulreed@paddedcell.com">paulreed@paddedcell.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Ala'a,<br>
<br>
On 2023-03-14 20:33, Ala'a Mohammad wrote:<br>
> I need help to understand the need to declare FOR loop stepping's<br>
> variable. (i.e x in FOR x := .....). I do not intend to change the<br>
> language, but The question arises since this variable always (in my<br>
> short exposure to Oberon-2) is scoped within the FOR loop body. And<br>
> was trying to answer the question:<br>
> Is it good design to have FOR implicitly declare its variable (It is<br>
> not a big issue to declare VARiables), or Is it from the point of<br>
> uniformity to have all variables declared with VAR?<br>
<br>
Thanks for a great question!<br>
<br>
FOR in the language report is defined to be equivalent to an assignment <br>
of the control variable (and the limit, in the case of Oberon-2; see <br>
below) followed by a WHILE loop containing the statement sequence and a <br>
fixed increment/decrement of the control variable.<br>
<br>
Therefore FOR *does not* introduce another scope, unlike in some other <br>
languages.<br>
<br>
And at first sight it seems there's nothing special about the control <br>
variable: as you say, for uniformity, it may be declared (and re-used) <br>
just like any other variable (at the beginning of the scope, or <br>
globally, which makes its type relatively easy to find).<br>
<br>
However, that the statement sequence must be executed "a fixed number of <br>
times", so implementations will typically make the control variable <br>
read-only (preventing assignments to it) inside the FOR. So it's a *bit* <br>
special. :)<br>
<br>
Some implementations might not necessarily protect the "fixed number of <br>
times", for example if they don't assign the limit expression to a <br>
temporary variable at the start of the loop. YMMV. Literally. :)<br>
<br>
HTH,<br>
Paul<br>
--<br>
<a href="mailto:Oberon@lists.inf.ethz.ch" target="_blank">Oberon@lists.inf.ethz.ch</a> mailing list for ETH Oberon and related systems<br>
<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer" target="_blank">https://lists.inf.ethz.ch/mailman/listinfo/oberon</a><br>
</blockquote></div>