#Code

40 messages · Page 1 of 1 (latest)

elfin hemlock
#

What is total and I doing here?

glossy wharfBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

gilded arch
#

total is an integer that is initialized to 0, and on every loop, if i is less than or equal to n, total's value increases by having the value of i added to it

#

i's value is also increased by 1 afterwards

#

so on the first loop you'd get total = 0 + 1 and i = 1 + 1

#

then on the second loop it'd become total = 1 + 2 and i = 2 + 1

#

if you've ever heard someone say the sum of x items/numbers, that's basically what total is here

elfin hemlock
gilded arch
#

because you incremented it

#

the variables' values persist through the loop

elfin hemlock
#

So every loop total increases by 1?

gilded arch
#

it increases by i

elfin hemlock
#

Total at first is 0

#

And then it’s 0 + 1

#

And why it’s not 0 (because by default is 0)+2 after

gilded arch
#

it's not 0 after, because 0 + 1 is not 0

elfin hemlock
#

Oh yeah sorry

#

I think I got it now,thank you so much

#

Sorry if I maybe annoying

gilded arch
#

you're fine

fresh gorge
glossy wharfBOT
#

@elfin hemlock Has your question been resolved? If so, type !solved :)

glossy wharfBOT
# glossy wharf

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

elfin hemlock
#

What would be if it wasn’t for total?

gilded arch
#

what would be what?

elfin hemlock
#

If total wasn’t here in this code

gilded arch
#

then you wouldn't have one

#

and you probably wouldn't print anything at the end

elfin hemlock
#

How the code would change?

gilded arch
#

or you'd print i

gilded arch
elfin hemlock
#

Total is the sum

#

Right

#

?

gilded arch
#

it acts as a sum, yes

#

besides that, it's inherently pointless

#

the code snippet just demonstrates a loop, none of the operations in the loop have any actual purpose beyond being there so you can see them

elfin hemlock
#

Ok