Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

You can control the flow of script execution by using the following types of statements to manage the order in which operations are executed:


Scroll only
scroll-viewporttrue
scroll-pdftrue
scroll-officetrue
scroll-chmtrue
scroll-

...

docbooktrue
scroll-

...

eclipsehelptrue
scroll-

...

epubtrue
scroll-

...

htmltrue
2


Use conditional statements (if, else, else if, switch)

...

Scroll pagebreak

IF statements

Anchor
IFState
IFState

The IF statement works as follows: if the test condition is true, the statement is executed.

...

Code Block
languagetext
if ( 2 < 3 )
 {
 string $blah = "This worked";
 print ($blah);
 }

Scroll pagebreak

ELSE statements

Anchor
ELSEState
ELSEState

The ELSE statement always follows the IF statement. The ELSE statement is executed when the preceding IF statement is false.

...

Scroll pagebreak

ELSE IF statements

Anchor
ELSEIFState
ELSEIFState

The ELSE IF statement is always paired with the IF conditional statement. Unlike the else command which executes a statement when the IF statement is false, the ELSE IF statement requires another test condition to be true, or it will not execute either statement.

...

Scroll pagebreak

SWITCH statements

Anchor
SWITCHState
SWITCHState

The switch statement is a conditional statement that executes a code block depending on which one of a number of given cases is matched to the switch expression.

...

Tip
Tip
You can use Interruption statements to affect the flow control in looping statements.

WHILE statements

Anchor
WHILEState
WHILEState

A WHILE looping statement continuously executes designated statements as long as a specific condition remains true.

...

Scroll pagebreak

DO WHILE statements

Anchor
DOWHILEState
DOWHILEState

A DO WHILE looping statement executes a specific statement then checks whether or not to repeat the loop. This ensures that the statement is executed at least once.

...

Code Block
languagetext
int $peanuts = 1;
 do {
 print ("Elephants work for peanuts");
 $peanuts += 1;
 print ($peanuts);
 }
 while ( $peanuts < 10);

FOR statements

Anchor
FORState
FORState

A FOR looping statement provides loop control that has initialization, test, and an increment statement.

...

Code Block
languagetext
// Courtesy of Jake Wilson of SCEA
// Initialize Variables
print " ";  
// Create array of children under 'Actor' Mary's character node
string $childarray[] = `getChildren Mary`;    
// Determine # of children
int $childcount = `getCount $childarray`;  
// Create a $childarrayloop to hold a number 
int $childarrayloop = 0;  
// Print an empty string
   string $ proptest;
// Start a loop which run once for each of Mary's children
for ( $childarrayloop=0 ;
 $childarrayloop < $childcount ;
 $childarrayloop +=1 ){
    // print name of current child marker in array   
    print ( string ($ childarray[$childarrayloop] ) );
    // return the name of the marker and compare the name 
    // of the marker to the name"LFWT"
    $ proptest = ` getStringProperty $ childarray[$childarrayloop] Name`; 
    if ($ proptest==LKNE){
        // if that LFWT marker is found, this tells the loop to quit
        $ childarrayloop=$childcount; 
        print ( "EXITING LOOP" );
        }
    }

Scroll pagebreak

Use interruption statements (break)

...