Script IF Statement

IF (condition) block [ELSE block]

The IF statement is used to execute one or more statements based on a condition or criteria.

The IF/ELSE statement forms a construct that decides which statement to execute next. If the condition is true, the statement or block directly following the IF is executed. If the condition is false, the statement or block directly following the ELSE keyword is executed. If the condition is false and there is no ELSE keyword, the statement following the end of the IF block is executed.

Use a BEGIN/END block when you want to execute more than one statement after IF or ELSE.

For example:

\* If no phone number was given, ask for it. Otherwise,
\* display the number. In either case, dial the number.
IF (_phoneno = "") BEGIN    \* multi-statement block
  ECHO "Enter phone number:"
  GET _phoneno
  END
ELSE
  ECHO "Dialing _phoneno"   \* single-statement block
SEND "ATDT _phoneno"

Note that the SEND statement is outside the IF/ELSE construct. It is executed regardless of the condition.

Copyright © 2017 American Chemical Society. All Rights Reserved.