+ Reply to Thread
Results 1 to 3 of 3

Thread: TI 82 calculator tutorials Part 2 - If statements and loops

  1. #1
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    TI 82 calculator tutorials Part 2 - If statements and loops

    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:

    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.


    TI 82 calculator tutorials Part 2 - If statements and loops-ti-82-test.jpg


    There's two way to create an if statement, the one witch only covers the next row and the multiline one.


    Singleline:

    Code:
    If X=3
    Disp "X IS EQUALS TO 3"
    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 1=0
    Disp "THIS WILL NOT BE DISPLAYED"
    Disp "THIS WILL BE DISPLAYED"



    Multiline:


    Code:
    If X=0:Then
    Disp "Nothing"
    1->X
    End
    In this multiline example everything until the end block will be executed if and only if X is equals to 0.





    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.

    Code:
    If X<0:Then
    Disp "X IS NEGATIVE"
    Else
    Disp "X IS POSITIVE"
    End
    So if X is less then 0, we'll be told X is negative. If it's not we'll be told its positive.









    For loops:

    The for loops are using 4 parameters:
    1. Variable name
    2. Start value
    3. End value
    4. Increaser

    Here's an example:

    Code:
    For(I,0,5,1)
    Disp I
    End
    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).

    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:


    Code:
    0->I
    While (I<4)
    Disp I
    I+1->I
    End
    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.

    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:


    Code:
    0->I
    Repeat (I=4)
    Disp I
    I+1->I
    End
    This code will continue to loop until I is equals to 4 at the end of the loop. The output will be:

    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.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: TI 82 calculator tutorials Part 2 - If statements and loops

    Very comprehensive! +rep

  4. #3
    Join Date
    Jul 2006
    Posts
    16,494
    Blog Entries
    75
    Rep Power
    143

    Re: TI 82 calculator tutorials Part 2 - If statements and loops

    Very good. +rep
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Loops and Do-While statements
    By vbstudent in forum Visual Basic Programming
    Replies: 7
    Last Post: 07-07-2010, 03:43 PM
  2. Replies: 10
    Last Post: 08-28-2009, 07:35 PM
  3. Replies: 2
    Last Post: 08-28-2009, 07:32 PM
  4. Replies: 2
    Last Post: 08-28-2009, 07:30 PM
  5. Replies: 6
    Last Post: 08-28-2009, 07:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts