Visibility of a var outside a cycle - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Visibility of a var outside a cycle (/thread-3319.html) |
Visibility of a var outside a cycle - salvomic - 03-09-2015 11:59 AM 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 RE: Visibility of a var outside a cycle - DrD - 03-09-2015 01:39 PM (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:
RE: Visibility of a var outside a cycle - salvomic - 03-09-2015 01:51 PM (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 RE: Visibility of a var outside a cycle - DrD - 03-09-2015 02:27 PM 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- RE: Visibility of a var outside a cycle - salvomic - 03-09-2015 02:40 PM (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 |