https://wiki.beyondunreal.com/w/index.php?action=history&feed=atomBreak statement - Revision history2017-11-18T03:07:00ZRevision history for this page on the wikiMediaWiki 1.25.1https://wiki.beyondunreal.com/Break_statement?diff=33156&oldid=prevWormbo: New page: 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 surround...2008-10-23T14:44:24Z<p>New page: The '''break''' statement can be used within <a href="/Do" class="mw-redirect" title="Do">do</a>, <a href="/While" class="mw-redirect" title="While">while</a>, <a href="/For" class="mw-redirect" title="For">for</a> and <a href="/Foreach" class="mw-redirect" title="Foreach">foreach</a> loops and within <a href="/Switch" class="mw-redirect" title="Switch">switch</a> blocks. Its effect is, that it immediately exits the inner-most surround...</p>
<p><b>New page</b></p><div>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.<br />
<br />
==Syntax==<br />
It's as simple as it can get:<br />
'''break;'''<br />
That's all. Just "break" and a semicolon.<br />
<br />
==Examples==<br />
When you use the '''break''' statement, you'll usually do it in the following way:<br />
<uscript><br />
while (/* condition */) {<br />
// some code<br />
<br />
if (/* required condition */)<br />
break;<br />
<br />
// more code<br />
}<br />
// break jumps here<br />
</uscript><br />
<br />
In nested loops, '''break''' only exits the inner-most loop:<br />
<uscript><br />
for (i = 0; i < 10; i++) {<br />
for (j = 0; i < 10; j++) {<br />
if (j > 5)<br />
break;<br />
}<br />
// break jumps here!<br />
}<br />
</uscript><br />
Note that UnrealScript provides no way to specify the loop to exit. It ''always'' exits the inner-most loop or switch.<br />
<br />
Sometimes you want to look for a single instance of a certain type of actor, for example a GameReplicationInfo:<br />
<uscript><br />
local GameReplicationInfo GRI;<br />
<br />
foreach AllActors(class'GameReplicationInfo', GRI)<br />
break;<br />
</uscript><br />
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.<br />
<br />
{{navbox unrealscript}}</div>Wormbo