1. ## Loop Question

i'm trying to study for an up comming test and i'm getting stumped on a few review questions..
"Determine the values of a loop counter and other values during the running of a program."

Code:
```   int x,y=0, value=24;

for( x=0, y=x+5;y<30;x++,y+=5)
{
value =value/y;
}```
value of x | value of y | value of value |
__________________________________________________ ___________
_____________|_____________________|______________ ___________|
_____________|_____________________|______________ ___________|
_____________|_____________________|______________ ___________|

what i see happening is x and y goes up by5 and every time value is dived by the growing y value un till y is just under under 30? so in 5 or 6 cycles? iam not to sure anymore

2. x starts at zero (x=0)
y starts at 5 (y=x+5)

x only goes up 1 per loop. (x++)
y goes up 5 per loop (y+=5)

value is divided (integer division) by y each loop.

The loop stops when y gets to 30 (y<30)

Todd

3. alright so then.....?

X ------- y ------- value
1 ------- 5 ------- 4.8
2 ------- 10 ------- 2.4
3 ------- 15 ------- 1.6
4 ------- 20 ------- 1.2
5 ------- 25 ------- 0.96
6 ------- 30 ------- 0.8

4. or do i divide the new "value" by the new "Y"

5. Originally Posted by fr0zen
or do i divide the new "value" by the new "Y"
Do you still have the old value of "value" any more? If so, where? If not, why not?

The words "integer division" mean something -- you should look them up.

You also need to double check your loop conditions.

6. what?

7. "value" originally had the value of 24. The second time through the loop, what is the value of "value"? Is it still 24, or is it something else?

8. thats what i was asking, does it save the new value or is value always the same... but iam thinking it changes, and i added some coding so that the program prints the numbers in the loop and i got

X ------- y ------- value
0 ------- 5 ------- 4
1 ------- 10 ------- 0
2 ------- 15 ------- 0
3 ------- 20 ------- 0
4 ------- 25 ------- 0
\ ------- \ ------- \

but some how that doesnt make sense? shouldn't it be till y equals 30? and value shouldnt it round up to 5, not 4.. it shouldn't have to include decimal answers since its and integer not a float right?

9. Originally Posted by fr0zen
thats what i was asking, does it save the new value or is value always the same... but iam thinking it changes,
You shouldn't have to guess; you have the code. The code says value=value/y. What does that statement do?

Originally Posted by fr0zen
and i added some coding so that the program prints the numbers in the loop and i got

X ------- y ------- value
0 ------- 5 ------- 4
1 ------- 10 ------- 0
2 ------- 15 ------- 0
3 ------- 20 ------- 0
4 ------- 25 ------- 0
\ ------- \ ------- \

but some how that doesnt make sense? shouldn't it be till y equals 30? and value shouldnt it round up to 5, not 4.. it shouldn't have to include decimal answers since its and integer not a float right?
You need to look up "integer division" in your textbook, since it's doesn't do what you think it does.

And look at your loop condition. If y is 30, is the condition true or false?