0

For(i=4; i<8 )

so in the start with i = 4 and I want to get

4+1=5

5+8=13

13/2=6

6+1=7

7+8=15

15/2=7

7+1=8

0,1,2,3,4,5,6,7,8

How do I do this?

1
  • For loops allow you to repeat an action a specified number of times. So in your example (i=4; i<8), you've set i to 4 (assuming you declared the variable i earlier in the program, and you want the loop to repeat until i is equal to 8. But you're missing an expression for how you want i to change as the loop runs. Review some of the class notes on for loops and look at examples to get a clearer picture of how they work and then outline what you want yours to do.
    – Scott J.
    Aug 14 '17 at 16:27
0

Think of a for loop as such:

FOR --> (some initial value ---> Check going until this is true ---> Incremental steps that will happen every loop)

for(Starting Value; Test for true; increment value)

for( a = 1; a (is less than) 5; a = (a(originally 1 but each times it goes up) plus 1)

for( a = 1; a < 5; a = a + 1)

Not the answer you're looking for? Browse other questions tagged .