2009-12-11, 18:46
#1
Hej jag skte lite p FB men hittade ingenting och frstr inte spec bra dem som ja hittat p engelska o s ... men jag undrar om ngon kunde frklara lite fr mig hur loops fungerar i perl ? lser i en fil men han frklarade lite konstigt ...
#!/usr/bin/perl
#Loop Tutorial
#By Warpboy
#www.securitydb.org
###################################
FULLY Commented
###################################
While Loops
#Format
# while (Comparison) {
# Action }#While loops will loop while the comparison is true, if it changes to false, it will nolonger continue to loop through its set of action(s).
$i = 1;
while($i <= 5) {
print "While:" . $i . "\n";
$i++;
}
#For Loops
#Format
# for (init_expr; test_expr; step_expr
{
# ACTION }
###
Init expression is done first, then the test expression is tested to be true or false
then --
# the step expression is executed.
for($t = 1; $t <= 5; $t++) {
print "For:" . $t . "\n";
}
##Continued to next page
#Until Loops
#Format
# until (Comparison) {
# Action }##
# An until loop tests the true false comparison, if it is true, it will continue to loopuntil the comparison changes to a
# false state.
$p = 1;
until($p == 6) { #It's six because when $p becomes = 5, it doesnt go through the
set of action sequences; therefore, 5 isn't printed.
print "Until:" . $p . "\n";
$p++;
}
#Foreach Loops
#Used most commonly to loop through lists
#Format
# foreach $num (@array) {
# Action }
$n = 1;
foreach $n (1..5) {
print "Foreach:" . $n . "\n";
$n++;
}
#End Tutorial
#Loop Tutorial
#By Warpboy
#www.securitydb.org
###################################
FULLY Commented
###################################
While Loops
#Format
# while (Comparison) {
# Action }#While loops will loop while the comparison is true, if it changes to false, it will nolonger continue to loop through its set of action(s).
$i = 1;
while($i <= 5) {
print "While:" . $i . "\n";
$i++;
}
#For Loops
#Format
# for (init_expr; test_expr; step_expr
![Whink](https://static.flashback.org/img/smilies2/wink.gif)
# ACTION }
###
Init expression is done first, then the test expression is tested to be true or false
then --
# the step expression is executed.
for($t = 1; $t <= 5; $t++) {
print "For:" . $t . "\n";
}
##Continued to next page
#Until Loops
#Format
# until (Comparison) {
# Action }##
# An until loop tests the true false comparison, if it is true, it will continue to loopuntil the comparison changes to a
# false state.
$p = 1;
until($p == 6) { #It's six because when $p becomes = 5, it doesnt go through the
set of action sequences; therefore, 5 isn't printed.
print "Until:" . $p . "\n";
$p++;
}
#Foreach Loops
#Used most commonly to loop through lists
#Format
# foreach $num (@array) {
# Action }
$n = 1;
foreach $n (1..5) {
print "Foreach:" . $n . "\n";
$n++;
}
#End Tutorial