FANDOM


The switch keyword is used to control the flow of a script. The general form of a switch statement is as follows:

switch (expression) {
case value0:
statement(s);
break;
case value1:
statement(s);
break;
. . .
case valueN:
statement(s);
break;
default:
statement(s);
}

Where expression is evaluated and the subsequently compared to the following case values. If a case matches the evaluated expression, the statement(s) associated with that case are executed. If no values match and a default statement exists, the statement(s) in the default case will be executed.
switch is used ONLY for expressions that evaluate to a numeric value.
Note: Unlike C/C++, the break statements in switches are superfluous. Torque Script will only execute matching cases and NOT automatically execute all subsequent cases. This is shown in the example below.

%tmp = 1;

switch( %tmp )
{
case 0:
echo( 0 );
case 1:
echo( 1 );
default:
echo( "proof" );
}

Switch

See Also Edit

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.