Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ifthenelse [2019/06/09 08:27] neilsifthenelse [2019/07/15 10:17] (current) neils
Line 3: Line 3:
 Syntax: Syntax:
  
- if <any relation> [and | or <any relation>] then <statements> [else <statements>]+  if <any relation> [and | or <any relation>] then <statements> [else <statements>]
   
 +or, since version 2.1:
 +
 +  if <any relation> [and | or <any relation>] then
 +    <statements>
 +  [else
 +    <statements>]
 +  endif
 +
 Conditional structure. Executes the statements after ''THEN'' if the expression evaluates to true, otherwise the statements after ''ELSE'', if present. ''ELSE'' is optional. Conditional structure. Executes the statements after ''THEN'' if the expression evaluates to true, otherwise the statements after ''ELSE'', if present. ''ELSE'' is optional.
  
Line 19: Line 27:
   
 Please refer to the [[operators|Operators]] page for the list of supported operators. Please refer to the [[operators|Operators]] page for the list of supported operators.
- 
-Since version 1.2, multiple statements can be written in one line using the statement separator character ('':''). This, in combination with the line concatenation character allows you to write multi-line ''IF ... THEN'' blocks: 
- 
- if x = y then ~ 
- print "the numbers are equal" : ~ 
- print "whatever else here" : ~ 
- eq = 1 ~ 
- else ~ 
- print "the numbers are not equal" : ~ 
- eq = 0 
-  
-The above is technically a single line in **XC=BASIC**. 
- 
-Note that no other characters are allowed after the ''~'', not even a whitespace! 
  
 ====== Performance tip ====== ====== Performance tip ======
  
 An ''ON ... GOTO'' or ''ON ... GOSUB'' construct is faster than its ''IF ... THEN GOTO/GOSUB'' equivalent. Please refer to the [[ON|ON construct]] for details. An ''ON ... GOTO'' or ''ON ... GOSUB'' construct is faster than its ''IF ... THEN GOTO/GOSUB'' equivalent. Please refer to the [[ON|ON construct]] for details.