http://calcg.org/newlogo2.png Not Logged in.
Login | Register

General Discussion Board \ Calculator Discussion \ If help!!!

Click here to log in (you must be logged in to post comments).

AuthorComment
thunderflea
Marine
Posted: 16 Nov 2009
14:06 GMT
Total Posts: 15
how would i make this shorter?
repeat K=105
getkey->k
if k=25:d+1->d <--------------
if k=25:p-1->P <--------------+
End |
|
how would i shorten this part |
to make it into 1 phrase.
haveacalc
Guardian
avatar
Posted: 17 Nov 2009
08:41 GMT
Total Posts: 1111
Repeat K=105
getKey→K
If Ans=25:Then
D+1→D
P-1→P
End
End


---
-quoted directly from most movies that don't exist (and some that do).
Vectris
Ultralisk
avatar
Posted: 17 Nov 2009
15:41 GMT
Total Posts: 375
You could also do it without using an explicit If statement like this.

Repeat K=105
getKey→K
D+(Ans=25)→D
P-(Ans=25)→P
End

haveacalc's is probably faster though as it only evaluates the variable Ans once whereas in this shorter but slower code it has to check the value twice.
darksideprogramming
Guardian
avatar
Posted: 11 Dec 2009
00:41 GMT
Total Posts: 1005
Pretty sure Vectris' method wouldn't work since the second Ans would be equal to D.
Vectris
Ultralisk
avatar
Posted: 19 Dec 2009
19:08 GMT
Total Posts: 375
I think your right, I don't work much with ans so I'd have to test which I'm to lazy to do right now. But looking back on this why is Ans even used? Why not just use K, or maybe I'm forgetting something cus this was a while ago.

Repeat K=105
getKey→K
D+(K=25)→D
P-(K=25)→P
End
haveacalc
Guardian
avatar
Posted: 19 Dec 2009
23:26 GMT
Total Posts: 1111
Ans is generally substituted where applicable because the interpreter registers that token with greater efficiency than it does letter variables. The example that you provided is redundant in that it tests a condition twice.

---
-quoted directly from most movies that don't exist (and some that do).





Portal | My Account | Register | Lost Password or Username | TOS | Disclaimer | Help | Site Search | File Archives Copyright © 2002-2019 CalcG.org