Variable declaration reset: Difference between revisions
m
→{{header|Raku}}: remove an untrue statement, rearrange slightly
m (→{{header|ALGOL 68}}: sp) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: remove an untrue statement, rearrange slightly) |
||
Line 163:
<pre></pre>
We can however, declare the variable with an "our" scope, which effectively makes it a package global.
<lang perl6>my @s = 1, 2, 2, 3, 4, 4, 5;
my $curr = @s[$i];
our $prev;
Line 178:
<pre>2
5</pre>
A better solution is to declare a state variable. A 'state' variable is essentially scoped similar to a 'my' variable (visible only inside the block), but is persistent across calls.
|