How would I go about using a value of user input to limit the terms in a for loop. The objective of the program is to let the user input the amount of terms, starting value, and counting interval. Thanks!
2 Answers
Your question is simple to answer by consulting TIBasicDev, specificly the pages for Input
, Prompt
, and For(
. Input
and Prompt
are self explanatory; they serve as two means of retrieving input from the user. For(
can take arguments to exhibit the behaviors you want.
Prompt
Prompt
is smaller and dirtier. The program
Prompt A
will result in the following output.
A=?
Input
Input
is the larger and cleaner option. The program
Input "ENTER VALUE:",A
will result in the following output
ENTER VALUE:
For
Taken from TIBasicDev:
The For loop takes four arguments: the variable (A-Z or theta), the starting value, the ending value, and the increment. It counts from the starting value to the ending value at the specified increment.
...
Format :For(variable,start,end[,increment]) :Command(s) :End
Writing your program will now simply require using the input commands to retrieve user input then using the for loop to create the desired effect.

- 1,732
- 1
- 19
- 28
As dohaqatar7 said, you can achieve your goal using the basic input commands. However, there is also a (slightly more advanced) way to allow users to input the values all at once, separated by commas. To do this, you input a string, store it into a built-in string variable like Str1
, then convert it to a list of numbers, and finally access each element of the list for the parameters in your For(
loop.
Input "START,END,STEP: ",Str1 //Whatever is input goes into Str1 as a string
//For example, "1,100,2"
expr("{"+Str1 //Then it is converted into a list like {1,100,2}
For(X,Ans(1),Ans(2),Ans(3) //Evaluates to For(X,1,100,2
[your code]
End
expr(
means expression, and basically tells the calculator to evaluate the string passed to it. But first, a {
is tacked on to the front so the calculator interprets it as a list, which is stored into the Ans variable. Individual elements of a list are accessed in the format [listname] (position), so Ans(1)
will get the first element of the list (in this case the start value 1) and so on.

- 592
- 4
- 15