Mostly Harmless

Continue statement

From Unreal Wiki, The Unreal Engine Documentation Site
(Redirected from Continue)
Jump to: navigation, search

The continue statement can be used in do, while, for and foreach loops to skip to the end of the current iteration step and reevaluate the loop condition to check if another iteration should be started. The for and foreach loops evaluate their update step first.

Continue is usually used to skip the rest of an iteration step if certain preconditions for the code are no longer met. Note that it is always possible to wrap the code in an if block instead, but sometimes a simple if...continue statement combination is much more elegant and expresses the problem more logically.

Syntax[edit]

Nothing special here:

continue;

Just the keyword "continue" followed by the standard semicolon to terminate the statement.

Examples[edit]

Let's say, you want to perform a certain operation for all NavigationPoint actors, but PlayerStarts also receive some kind of additional treatment. Without the continue statement you'd probably write:

local NavigationPoint NP;
 
/*
UE1/2 code here!
For UE3 you'd use:
foreach WorldInfo.AllNavigationPoints(class'NavigationPoint', NP)
*/
for (NP = Level.NavigationPointList; NP != None; NP = NP.NextNavigationPoint) {
  // generic code for all navpoints here
 
  if (PlayerStart(NP) != None) {
    // specific code for PlayerStarts here
  }
}

Using the continue statement you could reduce the number of nested blocks a bit:

for (NP = Level.NavigationPointList; NP != None; NP = NP.NextNavigationPoint) {
  // generic code for all navpoints here
 
  if (PlayerStart(NP) == None)
    continue;
 
  // specific code for PlayerStarts here
}

The resulting behavior is the same as in the previous example without continue. Note the reversed if condition!

It really depends on the situation whether to use the continue statement in a simple if or an if block. Don't just use either of them, just because they work. Think about which one makes more sense when trying to understand what the code does.