Break Statement

From NWN Lexicon
Revision as of 10:01, 21 August 2012 by Dood (talk | contribs) (Created page with "=break Statement= Used to escape from a looping structure ( switch case statement. <br /> If a break statement is executed from within a ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

break Statement

Used to escape from a looping structure ( switch case statement.


If a break statement is executed from within a looping code block the loop will halt execution regardless of the condition controlling the loop. Any remaining statements within the code block will not be executed.


If a break statement is executed from within a case inside of a switch statement, all following case statements are ignored.


The following example searches for a PC with a strength score higher than 12, and repeats until there are no more PCs to search:


object oTarget = GetFirstPC();

while (oTarget != OBJECT_INVALID) 
{
     int nStr = GetAbilityScore(oTarget, ABILITY_STRENGTH);
     if (nStr > 12) 
          break;
     oTarget = GetNextPC();
}

As soon as the loop finds a PC with a strength higher than 12 the break statement is called halting the loop and the search for a target. Note that if no PCs are present with a strength score higher than 12, the loop will not exit (seems to be a problem with GetNextPC).




 author: Ryan Hunt, editor: Charles Feduke, Mistress, additional contributor(s): Rich Dersheimer, Box, Scott Smith, bug finder: Pondo