WHILE/DO loops
homencsa resources partnershipsoutreachsoftware_tech
alliance searchinside ncsa adv_computingsciencedivisions
left up right comment

WHILE/DO loops

A language must have some form of flow control to be something better than a batch processor. The simplest form of flow control, beyond IF-ELSE is the DO loop. The first construct is the WHILE / DO loop:
 
	while ( EXPRESSION ) { 
		STATEMENTS; 
	} 
Note that the DO is implied. If the condition is initially false, the body of the loop will never execute. In the next form, the loop will execute at least once.
 
	do { 
		STATEMENTS; 
	} while (EXPRESSION); 
All loops support the following two control statements:
last
Declare that this is the last statement in the loop; completely exit the loop even if the condition is still true, ignoring all statements up to the loop's closing brace.
next
Start a new iteration of the loop
 
	# one way to count to 10 
	$number = 0; 
	while(1) { 
		$number++; 
		if ($number >= 10 )  { 
			last; 
		} 
	} 

left up right comment



NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

johnsonb@ncsa.uiuc.edu

Last modified: June 19, 1997



Retrieved by Memoweb from http://www.ncsa.uiuc.edu/General/Training/PerlIntro/do.html at 08/02/99