advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
IF...END IF Statement Details
  ◄Summary►  ◄Details►  ◄Example►                ◄Contents►  ◄Index►  ◄Back►
──────────────────────────────────────────────────────────────────────────────
 Syntax 1: Block Form
 IF condition-1 THEN
      [statementblock-1]
 [ELSEIF condition-2 THEN
      [statementblock-2]] ...
 [ELSE
      [statementblock-n]]
 END IF
 
 Syntax 2: Single-Line Form
 IF condition THEN statements [ELSE statements]
 
 Usage Notes
   ■ Use the object form of the IF statement to set up processing tasks
     specific to a particular control type. See: ◄IF TYPEOF Statement►
 
   ■ The single-line form of the IF statement is best for short,
     straightforward tests where only one action is taken.
 
   ■ The block form of this statement provides several advantages:
     • Adds structure and flexibility by allowing conditional branches across
       several lines
     • Tests more complex conditions
     • Allows you to use longer statements and structures
     • Allows program structure to be guided by logic rather than by the
       number of statements that fit on a line
     • Makes programs easier to read, maintain, and debug
 
   ■ In executing a block-form IF, Visual Basic tests the first Boolean
     expression (condition-1):
     • If the Boolean expression is True (nonzero), the statements following
       THEN are executed.
     • If the first Boolean expression is False (zero), Visual Basic begins
       evaluating each ELSEIF condition in turn.
 
   ■ When Visual Basic finds a true condition, the statements following the
     associated THEN are executed. If none of the ELSEIF conditions is true,
     the statements following the ELSE are executed. After the statements
     following a THEN or ELSE are executed, the program continues with the
     statement following the END IF.
 
   ■ The ELSE and ELSEIF blocks are optional. You can have as many ELSEIF
     clauses as you want in a block IF. Any of the statement blocks can
     contain nested block IF statements.
 
   ■ Visual Basic looks at what appears after the THEN keyword to determine
     whether an IF statement is a block IF. If anything besides a comment
     appears after THEN, the statement is treated as a single-line IF
     statement.
 
   ■ A block IF statement must be the first statement on a line. The ELSE,
     ELSEIF, and END IF parts of the statement can have only a line number
     or line label in front of them. The block must end with an END IF
     statement.
 
   ■ Statement blocks can include GOTO linenumber or GOTO linelabel
     directives. Note: GOTO is optional with a line number, but is required
     with a line label.
 
   ■ The single-line form is never required. Any program using single-line
     IF...END IF statements can be written using block form.
 
   ■ You can have multiple statements with a single condition, but the
     statements must be on the same line and separated by colons:
 
         IF A > 10 THEN A = A + 1: B = B + A: LOCATE 10,22: PRINT B,A