Site hosted by Angelfire.com: Build your free website today!
 
TBasic for Dummies
Lesson 3

    Welcome to Lesson 3! You have made it this far so why not take it a step further? In this lesson we will show you how to use the FOR(), WHILE(), and prompt/input. So let's get started already!

    The FOR() command is used as a loop function. I normally use it for a time de-layer, but it can be used to repeat a set number of commands over and over. It goes like this...

Program: Count
:For(A, 0, 20, 1)
:Disp A
:End

    This program is much like the other count programs but it stops at  20. Here is how it is coded. The A is the variable that is used to keep track of the count. The 0 is the starting value of A. The 20 is the stop value of A. The 1 is the increment (or the amount it goes up by each time it loops. The for command will repeat whatever is between it and the END. So in this program it will Disp A, 20 different times.

    Next is the WHILE() command. Much like For, it is used to repeat a single command over and over tell something stops it. Here is basically how you can use it...

Program: Count
:0->A
:While(A<21)
:Disp A
:A+1->A
:End

    This is another count program that will count to 20. It's another command that can be read out loud. While A is LESS THEN 21, DISPLAY A, Then add one to A and loop.  The While command will repeat whatever is between it and the end as long as the equation in the () is true.

    Next is the PROMPT and INPUT commands. They are used to let the user input a number or letter (if they put a letter in it will act as a variable). The only difference between the two is that PROMPT will put the variable name, an equals sign, and then a question mark. Input lets you put in text in asking the question. Here is and example...

Program: Count
:Prompt A                                                  /this asks for the starting value
:Input "stop value ", B                                 /this asks when you want it to stop
:For(C,A,B,1)
:Disp C
:end

    Notice the difference between the prompt and the input. I normally like to use the Input more because it can do more! Also Input has one more feature. If you put input on a line by itself it will take you to the graph and give you a pointer. Then when the user hits enter it will capture the X, Y values for the pointer. This feature is great for making RPGs and OSs for the 82. We won't go in depth on how it can capture the screen coordinates in this lesson. Both Input and Prompt give the user of the program the ability to set how the program will work.

QUIZ:
1. What will the calculator show if you put in PROMPT A?
A. A=?
B. A?
C. A=
D. A

2. In this for() statement when will it STOP? For(A,5,125,5)
A. When A=5
B. When A=25
C. When A=625
D. When A=125

3. When will While stop in this statement? While(A>125)
A. When A=125
B. When A=126
C. When A=124
D. BOTH A and B


Back to Contents
Next Lesson