The break statement can be used within do, while, for and foreach loops and within switch blocks. Its effect is, that it immediately exits the inner-most surrounding loop or switch block.
Syntax
It's as simple as it can get:
break;
That's all. Just "break" and a semicolon.
Examples
When you use the break statement, you'll usually do it in the following way:
while (/* condition */) { // some code if (/* required condition */) break; // more code } // break jumps here
In nested loops, break only exits the inner-most loop:
for (i = 0; i < 10; i++) { for (j = 0; i < 10; j++) { if (j > 5) break; } // break jumps here! }
Note that UnrealScript provides no way to specify the loop to exit. It always exits the inner-most loop or switch.
Sometimes you want to look for a single instance of a certain type of actor, for example a GameReplicationInfo:
local GameReplicationInfo GRI; foreach AllActors(class'GameReplicationInfo', GRI) break;
The AllActors iterator is canceled early here. This means, if there's any actor of class GameReplicationInfo, it'll end up being in the GRI variable. Without the break statement, the AllActors iterator would not only not stop at the first GameReplicationInfo. Additionally, the final content of the GRI variable is not defined. It might be the last GameReplicationInfo found, but it could also be None! The behavior depends on the implementation of the iterator function.
Declarations | Preprocessor • Classes • Interfaces • Cpptext • Constants • Enums • Structs • Variables (Metadata) • Replication block • Operators • Delegates • Functions • States • Defaultproperties (Subobjects) |
---|---|
Types | bool • byte • float • int • name • string • Object • Class • Enums • Structs (Vector ⋅ Rotator ⋅ Quat ⋅ Color) • Static arrays • Dynamic arrays • Delegates • Typecasting |
Literals | Boolean • Float • Integer • Names • Objects (None ⋅ Self) • Vectors • Rotators • Strings |
Flow | GoTo • If • Assert • Return • Stop • Switch • While • Do...Until • For • ForEach • Break • Continue |
Specifiers | Super • Global • Static • Default • Const |
UnrealScript | Syntax • .UC • .UCI • .UPKG • Comments • #directives • Native |