📖⚡IF

Performs a logic test and executes a section of code if the result was true.

Logic conditions are made up of values and logic operators (see todo: comparing values).

The expression can be extended by using logic conditional 📖⚡AND (Condition)  / 📖⚡OR (Conditional) statements.

Note: These extended statements are executed in the order they are written.

Any references to input pin variables default to the regular input port.

If you are using a Kic28 or Kic40 device and want to refer to inputs on PORTA & PORTC then please use the  📖⚡IF PORTA  & 📖⚡IF PORTC commands instead.


IF GOTO

IF Condition GOTO

Not recommended as it uses outdated GOTO command.

' IF GOTO Example
' Kic8
' ** Not recommended as it uses GOTO command **

  ' Initialise our variable
  LET B0 = 1
DO 

  IF B0 = 1 THEN GOTO MyLabel

  Continue:

LOOP 

MyLabel:
  TOGGLE 0
  GOTO Continue
END

IF GOSUB

IF Condition GOSUB

' IF GOSUB Example
' IF_GOSUB.txt
' Kic8
  
  ' Initialise our variable
  LET B0 = 1
DO 

  IF B0 = 1 THEN GOSUB MyLabel

LOOP 

MyLabel:
  TOGGLE 0
  RETURN

IF THEN

IF Condition THEN

  COMMANDS

ENDIF

' Testing For Input (IF)
' If1.txt
' Kic8 

  ' Our example assumes your device is connected to Pin1 
  SYMBOL MyDevice = Pin1

DO

  ' If your device is activated 
  IF MyDevice = 1 THEN

    ' Indicate something happening by toggling LED
    TOGGLE 0
    PAUSE 100

  ENDIF

LOOP

IF ELSE

IF Condition THEN

  COMMANDS

ELSE

  COMMANDS

ENDIF

' IF..ELSE Example
' Else.txt
' Kic8

  ' Our example assumes:  
  ' Button is connected to Pin1 
  ' LED is connected to output 0
  ' LED is connected to output 2

  SYMBOL MyDevice = Pin1
  SYMBOL MyLEDA    = 0
  SYMBOL MyLEDB    = 2 

DO
  ' If your device is activated 
  IF MyDevice = 1 THEN
    TOGGLE MyLEDA
  ELSE
    TOGGLE MyLEDB    
  ENDIF

  ' wait a short time
  PAUSE 100
LOOP

IF ELSEIF

IF Condition1 THEN

  COMMANDS

ELSEIF Condition2 THEN

  COMMANDS 

ENDIF

 

' IF..ELSEIF Example
' ELSEIF.TXT
' Kic8

' Simuate and notice the lines that are executed
DO 

  IF B0     = 0 THEN
    HIGH 0

  ELSEIF B0 = 1 THEN 
    HIGH 1

  ELSEIF B0 = 2 THEN 
    HIGH 2

  ELSE
    HIGH 4

  ENDIF

  LET B0 = B0 + 1
  PINS = 0

LOOP 
END


todo:

Tutorials: Simple Logic Comparing Values

See Also: SELECT   BRANCH   GOSUB   ONGOSUB   

Related Commands:

todo: Tutorials: Simple Logic