| Author |
Message |
TripleDuck
Joined: 10 Sep 2008 Posts: 2
|
Posted: September 10, 2008 12:18 PM Post subject: how to access individual list items from function parameter |
|
|
I'm writing a program/function and want to pass in a list, like:
In the program/function, how do I access each individual element? Supposing I want to return the value of all three numbers multiplied by each other?
I've tried using standard programming access with square brackets and it didn't work..
| Code: | (list)
Prgm
list[0]*list[1]*list[2]->mymult
EndPrgm
|
I've also tried using curly brackets and parentheses. None of these work. So, how do I access the individual elements?
Also, is there a way to obtain a count of the number of items in the list, so the program could do this for any number of items? |
|
| Back to top |
|
 |
calc0002
Joined: 01 Oct 2008 Posts: 4
|
Posted: October 3, 2008 9:29 AM Post subject: Lists |
|
|
| Code: | (list)
Prgm
list[0]*list[1]*list[2]->mymult
EndPrgm
|
There's only one thing wrong with the code you have there, and that is that lists in TI-BASIC start with the index 1, not 0. So you want:
| Code: | (list)
Prgm
list[1]*list[2]*list[3]->mymult
EndPrgm
|
If you want to have an unlimited number of elements, use the built in dim() function:
| Code: | (list)
Prgm
Local i,prod
1->prod
For i,1,dim(list)
prod*list[i]->prod
EndFor
EndPrgm |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
Saphic 1.5 // Theme created by Sopel
|
|