Home > lang > if 
 en fr de es it nl pl pt pt_BR mk sq ca hu cs tr ar fa id vi ko ru zh zh_TW eo
Previous  Next  Edit  Rename  Undo  Search  Administration  
Documentation  
Warning! This page is not translated.  See english version 
IF
IF Expression [ { AND IF | OR IF } Expression ... ] [ THEN ]
  ...
[ ELSE IF Expression [ { AND IF | OR IF } Expression ... ] [ THEN ]
  ... ]
[ ELSE
  ... ]
ENDIF

IF Expression [ { AND IF | OR IF } Expression ... ] THEN ...

Conditional control structure.

One-line syntax

You can write an IF ... THEN control structure on one line, provided that the true part of the conditional is written just after the THEN keyword. In that case, the THEN keyword is mandatory.

Short-circuit path

When you use several test expressions splitted by AND IF keywords, then they are evaluated from left to right until the first FALSE one is found, and then the test is FALSE. If all expressions are TRUE, then the test is TRUE.

When you use several test expressions splitted by OR IF keywords, then they are evaluated from left to right until the first TRUE one is found, and then the test is TRUE. If all expressions are FALSE, then the test is FALSE.

All that is different from using AND or OR that always evaluate its arguments.

You cannot mix AND IF and OR IF keywords on the same line.

Example

DIM k AS Integer

FOR k = 1 TO 10

  IF k < 5 OR IF k > 5 THEN
    PRINT k;;
  ELSE
    PRINT
    PRINT "5 has been reached!"
  END IF

NEXT

PRINT

1 2 3 4
5 has been reached!
6 7 8 9 10

If Pi > 0 Or If (1 / 0) > 0 Then Print "Hello"
If (Pi > 0) Or ((1 / 0) > 0) Then Print "World!"

Hello Division by zero

See also

Test Control Structures & Functions