IIF

Previous  Next

 

result = IIF( condition, value_if_true, value_if_false ) AS VALUE

 


 

Implements a Ternary Operator in MyBASIC2 and is a decision-making operator and it is an alternative for the if…else statement in MyBASIC2 programming language.

 

By using Ternary Operator, we can replace the multiple lines of if…else statement code into a single line in MyBASIC2.  The Ternary operator we will help you to execute the statements based on the defined conditions using comma (,) separated operator.

 

Example:

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Example of a using Ternary Operator function IIF

'

 

' Using IF THEN ELSE

IF COMPILED THEN

  PRINT "This is Kalle and he is Compiled",

ELSE

  PRINT "This is Kalle and he is NOT Compiled",

ENDIF

 

' Using IIF Ternary operator function

PRINT "This is Kalle and he is";IIF( COMPILED, " ", " NOT " );"Compiled",

 

END