INFO
	control structures - program flow control in LPC

DESCRIPTION
	This document deals with the control statements in the NannyMUD
	version of LPC. In all the following examples  is either a
	single expression or function call or it's a block of statements
	enclosed in { } . An expression is considered false in lpc _only_ if it
	is equal to the number zero, in all other caseses it is consider true.
	====================================================================  

	STATEMENT
		if - else - run on condition
	
	SYNOPSIS
		if( expression ) 
		or
		if( expression )  else 
	
	DESCRIPTION
		If is the simplest of all control structures, in the first form
		it runs the statement if the expression is true and in the
		second form it runs the first statement if the expression is
		true and the second if it is false.
	
	
	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	STATEMENT
		for - general loop statement
	
	SYNOPSIS
		for ( expression1 ; expression2 ; expression3 ) 
	
	DESCRIPTION
		the above statement is exactly equal to:
	
		expression1;
		while( expression2 )
		{
			
			expression3;
		}
	
	EXAMPLE
		int e;
		for(e=0;e<10;e++) write(e+"\n");
	
	SEE ALSO
		while, foreach
	
	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	STATEMENT
		while - execute a statement while an expression is true
	
	SYNOPSIS
		while( expression ) 
	
	DESCRIPTION
		While runns the statement until the expression is false. The
		expression is evaluated once for every loop. If the expression
		is false the first time the statement is never executed.
	
	SEE ALSO
		for, do - while, foreach
	
	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	STATEMENT
		do - while - execute a statement while an expression true
	
	SYNOPSIS
		do  while ( expression );
	
	DESCRIPTION
		do - while only differs from the ordinary while-loop in that it
		does _not_ evaluate the expression until after the statement
		has been executed once. Thus it always runs the statement once.
	
	SEE ALSO
		while, for, foreach
	
	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

	STATEMENT
		foreach - execute a statement for every item in an array

	SYNOPSIS
		foreach(variable, array)
 
	DESCRIPTION
		Execute statement once for each element in 'array', setting
		'variable' to one element of 'array' each time around. A
		'break' in the 'statement' will terminate the loop. A
		'continue' will continue the execution from the beginning of
		the loop with the next value.

	SEE ALSO
		while, do - while, for

	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	STATEMENT
		switch - case - Complicated conditional statement
	
	SYNOPSIS
		switch( expression )
		{
		  case constant1:
			
	
		  case constant2:
			
			break;
	
		  default:
			
		}
	
	DESCRIPTION
		Switch evaluates the expression give and then executes one or
		more statement accordingly to the result. If the result is
		equal to constant1 then statement1 will be executed, please
		observe that the second case-statement dos _not_ abort the
		execution in any way instead statement2 will also be
		executed. After that break will cause execution to continue
		after the after the last } in the switch statement. If the
		result is equal to constant2 only statement2 will be
		executed. In all other cases statement3 is executed because it
		is 'default'. Please note that the expression and constant can
		be either integers or string, but they can _not_ be mixed in
		the same switch-statement.

	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	STATEMENT
		break - break a loop or switch
	
	SYNOPSIS
		break;
	
	DESCRIPTION
		Break jumps directly out of any loop or switch statement. It is
		a very vital part of every switch statement.
	
	SEE ALSO
		do - while, while, for, switch
	
	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	STATEMENT
		continue - continue a loop
	
	SYNOPSIS
		continue;
	
	DESCRIPTION
		Continue work similarly to break only it does't finish the
		loop, it just aborts the rest of this turn in the loop. 
	
	BUGS
		Don't use it in conjunction with the switch-statement.
	
	SEE ALSO
		do - while, while, for
	
	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	STATEMENT
		return - return from a function
	
	SYNOPSIS
		return;
		or
		return expression;
	
	DESCRIPTION
		Return jumps directly out of a function returning the given
		value to the calling function. If no expression is given, 0 is
		returned.
	
	::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Help topics available:
C_vs_LPC Lesson1 README arrays block
class3 class4 class1 class2 control_structures
for foreach function inheritance keywords
learn_lpc/ lfuns lpc_standardized mappings operators
preprocessor profezzorn_has_the_word switch things_not_to_do types
virtual while

[START|BACK ]




[ NannyMuds main page | FAQ | Contact us ]

You are guest number 165 since November 2019.
This file was last modified: June 2000.