mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
revamped for loops
This commit is contained in:
parent
75ecb5aa81
commit
66379e80cd
@ -83,13 +83,23 @@ while (condition) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# for and foreach
|
# for loops and iteration
|
||||||
for ($i = 0; $i <= $max; $i++) {
|
for (my $i = 0; $i < $max; $i++) {
|
||||||
...
|
print "index is $i";
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (@array) {
|
for (my $i = 0; $i < @elements; $i++) {
|
||||||
print "This element is $_\n";
|
print "Current element is " . $elements[$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $element (@elements) {
|
||||||
|
print $element;
|
||||||
|
}
|
||||||
|
|
||||||
|
# implicitly
|
||||||
|
|
||||||
|
for (@elements) {
|
||||||
|
print;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user