Variable declaration reset: Difference between revisions

m
Line 337:
6
</pre>
Parenthetical note: making a global variable to support a for loop has a bad code smell in Julia. A better
way to do such a comparison of adjacent values in an array is to alter the start of the loop variable:
<lang julia>
s = [1, 2, 2, 3, 4, 4, 5]
 
for i in eachindex(s)[begin+1:end] # or 2:length(s)
s[i] == s[i - 1] && println(i)
end
</lang>
 
=={{header|Phix}}==
4,102

edits