while loops allow you to execute a group of statements so long as a statment still evaluates to true.
Here's a quick example;
Here's a quick example;
$num=20; while($num<30){ print "num is $num\n"; $num=$num+1; } this will print out num is 20 num is 21 ... num is 29
then num is incremented to 30 which is no longer less than 30 so the code within the while statement is not executed and execution jumps to the next statement outside of the while statement.
If you think you know all about while statements learn about his less popular brother until.
Edit Wed Aug 1 07:07:10 EDT 2001 - Petruchio Changed PRE tags to CODE tags, added whitespace.
Edit Mon Dec 02:27:42 EST 2004 - Petruchio changed '$while' to 'while', because this is in our Tutorials section, and should be accurate.
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: while loops
by Anonymous Monk on May 24, 2000 at 04:58 UTC | |
RE: while loops
by IainB (Initiate) on Oct 27, 2000 at 16:31 UTC | |
by Albannach (Monsignor) on Oct 27, 2000 at 17:40 UTC | |
by Anonymous Monk on Jan 30, 2001 at 11:18 UTC | |
by Anonymous Monk on Jun 06, 2001 at 15:33 UTC | |
by Anonymous Monk on Mar 08, 2001 at 10:57 UTC | |
Re: while loops
by rlivings (Acolyte) on Aug 01, 2001 at 14:02 UTC | |
by qwertydvorak (Initiate) on Aug 24, 2001 at 23:01 UTC | |
Re: while loops
by Glyndwr (Initiate) on Jan 11, 2002 at 18:35 UTC | |
by rob_au (Abbot) on Jan 11, 2002 at 18:41 UTC | |
by Glyndwr (Initiate) on Jan 11, 2002 at 19:11 UTC | |
by lvanhout (Curate) on Jun 15, 2004 at 17:42 UTC | |
Re: while loops
by Anonymous Monk on Oct 21, 2004 at 04:31 UTC |
Back to
Tutorials