Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

TI Source: Simple Loops
 
 Path: Home - Basic - Simple Loops    
  Basic    Assembly    Interactive    Miscellaneous    Members  

  Guide    Glossary    Programs  
 Simple LoopsBy Justin 

It is essential for you to be able to jump around in your code. Using blocks of code over again can save a lot of valuable space. The most basic way to jump around is using he commands Lbl and Goto.

Lbl stands for Label. It is used to label a line. When directing the flow of a program, you will need to refer to the line labels as the destination.

Goto stands for Go To. It tells the calculator where to go next in the program. This is where the line labels come in.


Breakdown of code:

Lbl Q
Label this line "Line: Q."
Disp "EXIT? 1=Y 2=N"
Display the text.
Input A
Ask the user to input a value to the variable A.
If A=1
Test A to see if it equals 1. If A does equal 1, then the next line will be executed. If A does not equal 1, the next line will be skipped.
Stop
Stop the program and return the home screen. (This will only happen if A=1)
If A=2
Test A to see if it equals 2.
Goto Q
Go to the line labeled Q. This will loop back to the beginning of the program.

Output:

Some rules for labels

  • The label can only be up to two characters long.
  • Any letter A through Z.
  • Any number 0 through 99.

    Remember not to use the Goto command too much. It is easy to get carried away and really mess up your code. If you get lost in your code because you have too many Goto loops, then you may want to look into some more efficient loops.

    Program Ideas:

    You may have noticed that the example program has a flaw. What would happen if the user entered a number other than 1 or 2? Edit the program to deal with this kind of user input.

  •  Downloads:
    TitleDescriptionAuthor
    simple_loops.zipAsk user if they want to exit.Justin
      Basic    Assembly    Interactive    Miscellaneous    Members