Available on: all targets

IF

The IF function allows you to evaluate whether a certain expression is TRUE (not 0) or FALSE. (0). Depending on that check, the function will return the second (if TRUE) or third (if FALSE) argument.

This function evaluates the expression at compile time: it follows that the return value does not change at runtime. There are three versions of this function, one for each type of value that can be returned. There is a version that returns integers, one for floating point numbers, and one for strings.

This function is particularly useful for carrying out a conditional evaluation of constants which, otherwise, would require evaluation at runtime, wasting time and occupying useless space.

SYNTAX

 = IF (exp, valueTrue, valueFalse )


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

EXAMPLE

 pictureToUse = IF(SCREEN WIDTH > 160, "large.png", "small.png" )


ABBREVIATION: If

Join BASIC 10Liner Contest with ugBASIC!

An interesting competition is held at the beginning of each year: the BASIC 10Liner Contest. It is possible to use ugBASIC to participate in the next "BASIC10Liner" competition, in the following categories:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

IF ↔ If

Any problem?

If you have found a problem with this keyword, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO KEYWORDS