Introduction | Language Structure | IB Statements | File System | Comet 32 Runtime | Index |
Syntax: |
IF relational-expression [THEN] conditional-statement(s) (or) IF relational-expression [THEN] conditional-statement(s) ELSE conditional-statement(s) ENDIF |
Discussion: |
There are two forms of the IF statement.
CRLIMIT GT 500In relational-expressions, the variable name always appears first, followed by a relational-operator from the following list: Relational operator Internet Basic syntax ============================================= Equal to EQ or = Not equal to NE or NOT= Greater than GT or > Greater than or equal to GE or >= Less than LT or < Less than or equal to LE or <=The comparison value is the third item in a relational-expression. It may be a constant or variable and must agree in data type with the variable name (i.e., strings must be compared to strings, numbers to numbers). Compound relational-expressions may be defined with the AND and OR parameters. These link individual relational-expressions -- the outcome is based on the joint outcome as follows: Parameter Conditions Outcome AND both conditions are true result is true AND at least one condition is false result is false OR either condition is true result is true OR both conditions are false result is falseIn compound expressions containing AND and OR, the AND parameter takes precedence (much like multiplication and division take precedence over addition and subtraction in a compound numeric expression). If multiple conditional-statements are to be executed, they must be separated with the ampersand character (&). If these statements exceed the length of a single editor line, they must be continued with the underline character (_). For an alternative syntax, see the IF/THEN/ELSE statement. |
Example 1: |
IF FLAG$ = "Y" THEN GOTO 9999 |
Example 2: |
IF A=B AND B=C THEN PRINT (0) "VALUES ARE ALL EQUAL." |
Example 3: |
If A=B OR B=C THEN PRINT (0) "SOME VALUES ARE EQUAL." |
Example 4: |
IF OPTION$="QUIT" THEN_ PRINT (0) "NOW ENDING PROGRAM" &_ CLOSE (1) & CLOSE (2) &_ RUN "QMONITOR" |
Example 5: |
IF OPTION$="QUIT" THEN PRINT (0) "NOW ENDING PROGRAM" CLOSE (1) & CLOSE (2) RUN "QMONITOR" ELSE PRINT (0) "PLEASE ENTER OPTION AGAIN:" INPUT (0) OPTION$ GOTO 500 ENDIF |