#Code
40 messages · Page 1 of 1 (latest)
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.
could you be more specific?
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
Why not total = 0 +2?
So every loop total increases by 1?
it increases by i
Total at first is 0
And then it’s 0 + 1
And why it’s not 0 (because by default is 0)+2 after
it's not 0 after, because 0 + 1 is not 0
you're fine
It isn't by default. It is 0 at the start, bc it was initialized with that value^^
Alright got it
@elfin hemlock Has your question been resolved? If so, type !solved :)
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
What would be if it wasn’t for total?
what would be what?
If total wasn’t here in this code
How the code would change?
or you'd print i
you'd remove everything relating to total
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
Ok