The While Loop loops until a condition you give it is false.
The above code will, like the code before it, print out the numbers 1 through 9, stopping once the value becomes equal to ten and the statement is false.
Foreach There is Another!
Our final Loop is known as the Foreach Loop and is used mostly with arrays.
@breakfast = ("Sausage", "Eggs", "Bacon", "Grits", "Toast" "Hash");
print "My breakfast:nn";
foreach $breakfast (@breakfast)
This code access the values in your array and prints them one by one:
And that is it for Loops and Conditionals. In my next tutorial, I will go over a few more statements, and we will learn to work with files -- creating them, reading them, writing them, you name it.
So go forth, young nerdling, and use your Perl wisdom for great deeds. Till then...
blog comments powered by Disqus