Visibility of a var outside a cycle
|
03-09-2015, 11:59 AM
Post: #1
|
|||
|
|||
Visibility of a var outside a cycle
hi,
I've a code like this one: Code:
now, tn is actually 1024 (i.e.), outside the FOR cycle "Return tn" give 1024, but "return tn^2) give 1449616 and not the right value (1048576); "return tn*2" give correctly 2048, "return tn*tn" give also 1449616... How must I set the variable to give the correct value, also with tn^2 and so on, outside the cycle? Thanks! Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
03-09-2015, 01:39 PM
Post: #2
|
|||
|
|||
RE: Visibility of a var outside a cycle
(03-09-2015 11:59 AM)salvomic Wrote: now, tn is actually 1024 (i.e.), outside the FOR cycle "Return tn" give 1024, but "return tn^2) give 1449616 and not the right value (1048576); "return tn*2" give correctly 2048, "return tn*tn" give also 1449616... Code food for thought: Code:
|
|||
03-09-2015, 01:51 PM
Post: #3
|
|||
|
|||
RE: Visibility of a var outside a cycle
(03-09-2015 01:39 PM)DrD Wrote: Code food for thought: always thank you you're code was ok! However sorry for my stupid question: I had actually 1204 and I read "1024", so I was so silly confused. Too hurry... Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
03-09-2015, 02:27 PM
Post: #4
|
|||
|
|||
RE: Visibility of a var outside a cycle
Yes, (1024,1204), I was going to mention that, as an interesting 'twist' on the inner digits, but I thought it too obvious to mention. From your code fragment, I couldn't determine what you were actually working with, so I just made up a dummy list (DL) that equates to the coded example, returning your expected result. Within that there may be a useful hint(s) you might find useful to actually accomplish your own objectives.
Over the years, I've grown fond of using lists. In general they are much faster more efficient, and powerful, (for me), to understand than matrices, and I find them to be way easier to work with, even though I have recently completed a couple of courses in linear algebra. While fun to do at the time, trying to remember all the various rules and tools of matrices is a true case of diminishing returns, in my case! -Dale- |
|||
03-09-2015, 02:40 PM
Post: #5
|
|||
|
|||
RE: Visibility of a var outside a cycle
(03-09-2015 02:27 PM)DrD Wrote: Yes, (1024,1204), I was going to mention that,... yes, Dale, I agree: I love "too much" Linear Algebra and matrices, but with Prime I'm finding out the lists, and they are enough powerful! I'm using they in my last programs. Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)