switch

MudOS_0.9.18/doc/lpc/constructs/switch · 821 B

From the archive MudOS_0.9.18.tar.gz

Download the archive   « Back to the archive contents

* The switch statement.  The LPC switch statement is nearly identical to
the C switch statement.  The only real difference is that the cases of
the LPC switch may be strings as well as integers.  Syntax is as follows:

switch (expression) {
	case constant0 : statements0;
		break;
	case constant1 : statements1;
		break;
	default : statements2;
		break;
}

The switch is a replacement for the chained if else if else if else
construct.  The above switch is equivalent to:

tmp = expression;
if (tmp == constant0) {
	statements0;
	...;
} else if (tmp == constant1) {
	statements1;
	...;
} else {
	statements2;
	...;
}

The main difference between the switch and the if statement is that if
the "break;" statement is ommited from the end of a particular case,
then the statements in the next case will be executed as well.

Site Stats

Snippets: 1791
Codebases: 571