Export (0) Print
Expand All

Control Structures 

For all control structures except the switch statement, transfer of program control is based upon a decision, the result of which is a truth statement (returning a Boolean true or false). You create an expression and then test whether its result is true. There are two main kinds of program control structures.

Selection Control Structure

The selection structure specifies alternate courses of program flow, creating a junction in your program (like a fork in a road). Four selection structures are available in JScript.

  • the single-selection structure (if)

  • the double-selection structure (if...else)

  • the multiple-selection structure (switch)

  • the inline conditional operator ?:

Repetition Control Structure

The repetition structure specifies the repetition of an action while some condition remains true. When the conditions of the control statement have been met (usually after some specific number of iterations), control passes to the next statement beyond the repetition structure. Four repetition structures are available in JScript.

  • the expression is tested at the top of the loop (while)

  • the expression is tested at the bottom of the loop (do...while)

  • operate on an object's properties or an array's elements (for...in)

  • counter controlled repetition (for)

Combination Control Structure

Complex scripts nest and stack selection and repetition control structures.

Exception handling, which provides another way to control program flow, is not covered here. For more information, see try...catch...finally Statement.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft