Forums Register Login

simple question with variable declaration and reset variable to init state

+Pie Number of slices to send: Send
simple code



why variable is a=6 and not 10 in the last 2 lines?
Is it possible to reset variable a as it was declared a=10?

run:
test
10
9
8
7
6
1006
1
+Pie Number of slices to send: Send
because you are changing it in your loop on line 10.

and if you want to reset it to 10, just put in

a = 10;

alternatively, you could copy the value of a to some temp variable, use that in your loop, and a would remain unchanged.
1
+Pie Number of slices to send: Send
In your code you have this block:

What line 5 says is:
1. Take variable a
2. Subtract 1 from it
3. Store whatever that number is into a.

So basically the reason that a does not equal 10 at the end of your program is because it is being overwritten each time by line 5 in the code block above.
a wee bit from the empire
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 425 times.
Similar Threads
Reverse Int, char, double
Divisor or prime problem
equals versus ==
varargs - method resolution principle???
reference variables
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:46:57.