Site hosted by Angelfire.com: Build your free website today!

Lesson 6 - If Then (Else) End statements



    If Then (Else) End statements can be used in many ways.  I will model For and Else in the getky lesson, and If and Then will be modeled here.  "If" simply says if a statement is true, do this, and if it isn't, do this then End the If statement:

    Take the program section from Lesson 5 and modify it to make the text bounce back and forth with If and Then:

:ClLCD                     ;Clears the home screen
:1->A                        ;Stores 1 to the variable "A"
:Lbl Top                    ;Identifies label Top
:Outpt(2,A,"Hi"       ;Outpt(2,A - A stands for 1, then two, etc.
:For(I,1,200             ;For counts from 1 to 200 before continuing to ClLCD
:End                          ;Ends the "For" statement
:ClLCD                     ;Clears the homescreen
:A+1->A                  ;Adds one to variable "A"
:If A==19                 ;If A is equal to 19 reverses the direction
:Then
:Goto Reverse
:End                         ;If A isn't equal to 19, continues after end
:Goto Top
:Lbl Reverse
:Outpt(2,A,"Hi"
:For(I,1,200
:End
:ClLCD
:A-1->A                  ;Subtracts 1 from A and stores the result
:If A==1                  ;Goes to Top if true (A==1) or goes to Reverse to continue moving A
:Goto Top
:Goto Reverse