The left and right side differs in more than one way; in the right
example you have correctly placed the boolean inside the loop so that
it will be read each time. In the left example the initial value will
be passed to the loops and that's all. Incorrect data flow.

If you use two while loops then it's often OK to use a local,
especially if it's something as simple as a switched boolean (it's
therefor often used e.g. to stop multiple loops). In this case the
boolean is a switch and there is little chance of a race problem
(which you could have if it was latched; then the first loop might
have reset the button before the second one has reacted to the initial
value change).

Could the local be avoided? Well - the second loop could perhaps be
avoided, depend on what else you want to do in the loop. With a second
loop though you could use an occurence, notifier, functional global
etc (a bit of an overkill here though) - there are  a number of
options. Again - for something simple a local is OK. Often people with
experience with textual languages use locals everytime they need the
data though; no wiring at all...

Reply via email to