In this series of tutorials I will teach you how to program in a TI 82 calculator from the very basics. I use a TI 82 calculator and therefor I also use it for my examples but many different Texas Instruments calculator has nearly the same syntax so you don't have to use it with a TI 82.
All my knowledge I have got by testing on boring math lessons so I've tried a lot and know what to do and what you shouldn't do.![]()
Parts in this series:
- Part 1 - The very basics
- Part 2 - If statements and loops
- Part 3 - Receiving Inputs
- Part 4 - Matrixes and Lists
- Part 5 - Creating a Game
Anyway, let's start with Part 2 - If statements and loops.
To insert logical operators and relational operators press the "2nd" button and then the "MATH" button.
There's two way to create an if statement, the one witch only covers the next row and the multiline one.
Singleline:
This is how you write a singleline if statement. If X is equals to three the next row will be executed to display the message. I'll give you an example what I mean with single line.Code:If X=3 Disp "X IS EQUALS TO 3"
Code:If 1=0 Disp "THIS WILL NOT BE DISPLAYED" Disp "THIS WILL BE DISPLAYED"
Multiline:
In this multiline example everything until the end block will be executed if and only if X is equals to 0.Code:If X=0:Then Disp "Nothing" 1->X End
More advanced if Statements:
It's also possible to add logical operators and different relational operators. Just add as many as needed. Here's an example.
Code:If (X=0 and Y=1) or (X<0 or (P=23 and Y>3)):Then Disp "INSIDE THE IF STATEMENT" End
If else statement:
If we use the multiline way we can also add an else block, this will occur if the conditions aren't met.
So if X is less then 0, we'll be told X is negative. If it's not we'll be told its positive.Code:If X<0:Then Disp "X IS NEGATIVE" Else Disp "X IS POSITIVE" End
For loops:
The for loops are using 4 parameters:
1. Variable name
2. Start value
3. End value
4. Increaser
Here's an example:
This for loop is using the I variable(1st parameter) and set its value to 0(2nd parameter). Then if I is equals to 5(3rd parameter) when the loop reaches the end the loop will end or else it will start from the beginning again. At the end each time I will increase by 1(4th parameter).Code:For(I,0,5,1) Disp I End
So that code will generate this output:
Code:0 1 2 3 4 5
While loops:
The while loops is not so complicated at all, they just loop while the conditions are true:
This first sets I's value to 0. Then the while lop will continue while I is less then 4. Inside the loop we first displays the value of I and then increase it by one.Code:0->I While (I<4) Disp I I+1->I End
The output will be this:
Code:0 1 2 3
Repeat loops:
The repeat loop is what usually is called a do until loop. Each time the loop reaches the end it will check if the conditions are met, if they are the loop is exited. Here's an example:
This code will continue to loop until I is equals to 4 at the end of the loop. The output will be:Code:0->I Repeat (I=4) Disp I I+1->I End
Code:0 1 2 3
Since the conditions are checked at the end this code will display "LOOP" even though the conditions are already met in the beginning:
Code:0->I Repeat (I=0) Disp "LOOP" End
That's all for Part 2, see you soon in Part 3![]()
Last edited by Vswe; 08-28-2009 at 04:19 PM.
Very comprehensive! +rep
Very good. +rep
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks