IF ELSE
homencsa resources partnershipsoutreachsoftware_tech
alliance searchinside ncsa adv_computingsciencedivisions
left up right comment

IF ELSE

Conditionals are put to use in IF THEN ELSE. The following are acceptable uses of IF:
 
	if (EXPRESSION ) { 
		STATEMENTS; 
	} 
	 
	if (EXPRESSION ) { 
		# executed if true 
		STATEMENTS; 
	} ELSE { 
		# executed if false 
		STATEMENTS; 
	} 
 
	if (EXPRESSION ) { 
		STATEMENTS; 
	} elsif { 
		STATEMENTS; 
	# optional additional ELSIF's 
	} else { 
		STATEMENTS; 
	}	 
This is the first time we've seen the { } (braces) used outside the context of associative arrays. In addition to denoting the key for an associative array, they are used to mark of blocks of expressions. Any number of statements can be part of the true or false portions of the IF ELSE, and the braces are to enclose all of them. Unlike C, the braces are not optional - requiring braces avoids the dangling else problem

Perl has no SWITCH statement - it can be imitated several ways, including using ELSIF for each possible case.


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/if-else.html at 08/02/99