Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: AGVolnutt on May 26, 2011, 08:04:53 pm

Title: (removed)
Post by: AGVolnutt on May 26, 2011, 08:04:53 pm
(removed)
Title: Re: Some code assistience.
Post by: Freyaday on May 27, 2011, 03:19:06 am
Whilst editing a program, press PRGM and then press 4
Congratulations! you now have a For( in program!
This is the command for a For loop. The syntax is
For(VAR(A~theta),starting value, end value[, increment]
.code goes here
End
The part in brackets is optional. If you leave it off, the increment is 1.
What a For loop does is it sets VAR to the starting value, executes the code, adds Increment to VAR, then checks to see if VAR is > (< if increment is negative) the ending value, and loops if it isn't.
Title: Re: Some code assistience.
Post by: AGVolnutt on May 27, 2011, 11:48:58 am
Thanks but...
That's for TI-84. XD

I forgot to mention I'm working with nSpire code.
Sorry.

BUT! I did look up the "For" command in my reference guide. I'll take your advice and be sure to figure out how it works!

Thank you!
Title: Re: Some code assistience.
Post by: Freyaday on May 27, 2011, 02:36:53 pm
I think For loop syntax doesn't change much, if at all, between languages, it's a pretty common structure, but it can't hurt to check. Oh, and I forgot to mention that an increment of 0 is never valid
Title: Re: Some code assistience.
Post by: AGVolnutt on May 27, 2011, 05:50:32 pm
SO
I think For loop syntax doesn't change much, if at all, between languages, it's a pretty common structure, but it can't hurt to check. Oh, and I forgot to mention that an increment of 0 is never valid

So I should make sure that my inputted n is +1'd before I the program goes on, right?
Title: Re: Some code assistience.
Post by: Freyaday on May 27, 2011, 06:07:31 pm
No, that's not it. In fact, a For loop sets the variable to the starting value at the very beginning.
What I meant was that
For(foo,bar,baz,0
is invalid code in any language, because the increment is 0
Title: Re: Some code assistience.
Post by: Runer112 on May 27, 2011, 06:11:42 pm
An increment of zero can be valid in some languages. It will just likely freeze/crash your program unless you manually increment the variable yourself or jump out of the loop. :P