If/Then

What is If and what is Then?

If and Then are commands that tell the calculator when to do something, and what to do. It is simple.
A completed If and If/Then command might look like this:

If A=5
PROGRAMMING

or

If A=7
Then
PROGRAMMING
PROGRAMMING
End

If is used to show that you want whatever you program next to accure when the statement happens. Such as, 'when A=5, do this...'
However, if you want more than one thing to happen, like if A=5 and you want three things to occur, you need to use the "Then" command. "If" (by itself) is used when you only want one thing to happen. Like:

If A=9
Output(5,7,"Hi

'Then' would work when more then one thing happens, like:

If A=4
Then
Output(4,1,"Hi
Output(3,1,"There
End

Notice how I used End at the end of every 'Then' statement. You must have this or the program will mess up and quit.
If you want to make a simple fortune teller program, you can use the If/Then statements. Below is a sample fortune program.

randint(1,4)->A
If A=1
Disp "Yes
If A=2
Disp "No
If A=3
Disp "Maybe
If A=4
Then
Output(1,1,"Could
Output(2,1,"Happen
End

This choses a random number from 1 to 4, and displays text corrosponding to whichever number is chosen. Simply, isn't it? Again, notice how I used "Then" and "End" when I had to place two text messages.

Back to the homepage.