Jump to content

Loops/Nested: Difference between revisions

Added Pike implementation
(Added Pike implementation)
Line 2,694:
(printsp N)
(and (= N 20) (throw)) ) ) )</lang>
 
=={{header|Pike}}==
 
Pike does not have a generic goto, but break is a special case in that
you can specify labels and break several levels of loop. In practise
this is extremely seldom used in favor of using a state variable or
containing the nest in a function that you <tt>return</tt> from in the
inner loop. However it's there if you want it:
 
<lang>
int main()
{
// enumerate() normally returns a linearly enumerated array, but
// allows for the forth argument to specify a function that will
// be called and return the value that should be in each cell. We
// create an anonymous function (lambda) that just returns a
// random value.
array a = ({});
for(int i=0; i<20; i++)
a += ({ enumerate( 20, 1, 1, lambda(){return random(20)+1;} ) });
 
// We could use for() and a[x][y] indexing, but foreach is just
// shorter and easier to use even if the 2D-array becomes less
// obvious.
mynestedloops:
foreach(a, array inner_a) {
foreach(inner_a, int value) {
write(value +" ");
if(value == 20)
break mynestedloops;
}
}
write("\n");
}
</lang>
 
=={{header|PL/I}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.