Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Return Functions

Author
Message
AAChaoshand
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 6th Jan 2016 19:43 Edited at: 6th Jan 2016 19:47
Having a hard time working the logic out on this one. Need some guidance here as I am either not understanding the syntax correctly or am getting lost in the logic somewhere...



How is this returning the sum of all integers? From what I can gather, the following is happening:

result = 0 and c = 1 on first iteration
increment result so result = 1, c = 1
next c

next iteration
result = 1, c = 2
inc result, c
blah

rinse and repeat right? How is anything being added together? Am I missing a vital part? So if I say SumIntegers(4) it would be 1 through 4 in iterations but where is the math done to add each one? Is that where the increment line comes into play?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jan 2016 19:57 Edited at: 6th Jan 2016 19:58
Quote: "inc result, c"


This adds c to the current value of result each loop. In simple terms:

Loop 1:
result = 0 + 1 : 1

Loop 2:
result = 1 + 2 : 3

Loop 3:
result = 3 + 3 : 6

Loop 4:
result = 6 + 4 : 10
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
AAChaoshand
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 6th Jan 2016 20:05 Edited at: 6th Jan 2016 20:05
Hmm, so why not inc result + c.... wait I think I understand now, scratch that last statement. So it's increment result by c then and once that is complete then it cycles again until v has been reached incrementing as it goes. the "result" variable acts as a placeholder for the next iteration then.
AAChaoshand
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 6th Jan 2016 20:29 Edited at: 6th Jan 2016 20:29
Looking further into this, I see



To me, this makes way more sense as you are just adding on. More than one way to skin a cat assuming I am seeing this correctly now?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Jan 2016 12:41
Yes, it is the same result, different way of skinning the cat
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-04-19 08:41:32
Your offset time is: 2024-04-19 08:41:32