Variable declaration reset: Difference between revisions

m
no edit summary
m (→‎{{header|Raku}}: left a word out)
mNo edit summary
Line 4:
Using a straightforward longhand loop as in the JavaScript and Phix examples below, show the locations of elements which are identical to the immediately preceding element in {1,2,2,3,4,4,5}. The (non-blank) results may be 2,5 for zero-based or 3,6 if one-based. <br>
The purpose is to determine whether variable declaration (in block scope) resets the contents on every iteration.<br>
There is no particular judgement of right or wrong here, just a straightforwardplain-speaking statement of subtle differences.<br>
Should your first attempt bomb with "unassigned variable" exceptions, feel free to code it as (say)
// int prev // crashes with unassigned variable
7,806

edits