Main Index : Reference :
do-while
loop, a for
loop or a switch
statement.
break;
break
can be used in two ways, depending on the context. Within a do-while
or for
loop it exits the loop before the loop expression has become false. Within a switch
statement it is used to skip the rest of the case:
tags.
// The for loop will only run 5 times. Afterwards,
// a will be 10 (0+1+2+3+4).
var i, a = 0;
for (i=0; i<10; i++)
{
if (i==5) break;
a += i;
}
// So will this do-while loop. Again, a will be 10 afterwards.
var i = 0;
var a = 0;
do
{
if (i==5) break;
a += i;
i++;
}
while (i<10);
// Using break correctly is important in switch statements,
// otherwise all cases are executed.
//
// Outputs "It's a number.".
var x = 5.5
switch(typeof(x))
{
case DT_INT:
case DT_FLOAT:
println("It's a number.");
break;
case DT_STRING:
println("It's a string.");
break;
default:
println("I don't know what it is.");
}