Heaney
Soft
HeaneySoft's BASIC Tutorial
Section 4: Conditional Statements
There's really only one conditional statement that the TI-83 has to offer, and that's the if statement, a very powerful tool.
If, Then, and End:
The If statment isn't hard to understand at all. Basically, you give the program a relational statement (using equals, greater than, less than), and it figures out if that statement is true. If it is true, the program will go to the Then statement and it will do any commands that follow it until it finds the End statement, after that the program continues like normal. So an If, Then statement would look like this:
:Prompt A
:Prompt B
:If A>B
:Then
:Disp "A IS GREATER","THAN B"
:End
I used Prompt in this situation just to make the program simpler. The End statement is very important, if you forget to put the End statement you could have major problems. For instance, if A>B is false, the program would skip the Then statement and look for an End, chances are it won't find one. There is a way to write the If statement without a Then, but there must be only one command. This is how you do it:
:Prompt A
:Prompt B
:If A>B:Disp "A IS GREATER","THAN B"
In this case, the colon (:) acts as the Then statement. Now it's time to learn how you can use the If statement even if it's false.
If, Then, Else, and End:
Here we introduce the Else statement. Lets consider the example above. What if we wanted it to tell us that A was less than B, if that was the case. This is what we could do:
:Prompt A
:Prompt B
:If A>B
:Then
:Disp "A IS GREATER","THAN B"
:Else
:Disp "A IS LESS","THAN B"
:End
The Else is where the program will go if the If statement is false, it just skips right past the Then statement. Now you know how to make conditional statements. It's very easy to make mistakes using conditional statements, so check everything you do, and always make sure to use the End statement whenever there's a Then.
Section 3 | Index | Section 5
Comments, Questions, or Ideas: Click Here | Home
Copyright © 2004 HeaneySoft