Variable declaration reset: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Created Nim solution.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(2 intermediate revisions by one other user not shown)
Line 427:
end
</syntaxhighlight>
 
=={{header|K}}==
There is no such thing as a <i>straightforward longhand loop</i> in K. See also: https://nsl.com/
 
A natural expression for finding the indices of repeated elements (in [[ngn/k]]) might be:<syntaxhighlight lang=K>&=/'2':1 2 2 3 4 4 5
1 4</syntaxhighlight>
 
But of course, there's no variables here.
 
Longhand loops can be emulated, using lambdas (in which case local variables expire when the lambda exits), but this is not what many programmers would think of as a straightforward longhand loop.
 
=={{header|Nim}}==
Line 775 ⟶ 785:
=={{header|Wren}}==
Note firstly that unassigned variables are impossible in Wren. If a variable is created without giving it an explicit value, then it is assigned the special value 'null' which is the only instance of the Null class and therefore distinct from all other values in the language.
<syntaxhighlight lang="ecmascriptwren">var s = [1, 2, 2, 3, 4, 4, 5]
 
// There is no output as 'prev' is created anew each time
9,476

edits