"...and while loops don't seem to work either. If i put a number for example x < 900 then the script is executed perfectly but if i leave something like x < links then it doesn't..."
while loop should work, the issue is the condition you give to the while loop (whether you take any sanp shot):
use strict; use warnings; my @array = (1 .. 4); while (@array) { my $first = shift @array; print "[$first]"; push @array, $first / 2 if (!($first % 2)); }
This prints the correct answer:
[1][2][3][4][1][2][1]
A for loop works as well, as long as you don't take any snap shot:
use strict; use warnings; my @array = (1 .. 4); for my $element (@array) { print "[$element]"; push @array, $element / 2 if (!($element % 2)); }
This also gives the correct answer.
In reply to Re: Processing a dynamic array
by pg
in thread Processing a dynamic array
by lampros21_7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |