0

So I have been trying to initiate the bricks for breakout in pset3. But the outcome of my nested loop is this :

enter image description here

I don't understand why I get 10 rows and 5 columns of bricks, rather than 5 rows and 10 columns. Can someone explain to me why this happens?

Here is the code I have written :

enter image description here

2

It looks like your intent is to create the bricks by rows, meaning that you are creating each row with the inner loop and switching to the next row with the outer loop. However, you are incrementing the y coordinate on the inner loop. This means that you're creating the bricks by columns. If you want to see it happen, insert the following line inside the inner loop:

for( time = 0; time < 1000000; time++);  // slows display of bricks.

You might have to play with the 1000000 to get a nice speed that you can see the progression.

Try changing the code so that the x coordinate is incremented on the inner loop and the y coordinate is changed on the outer loop.

If this answers your question, please mark it as answered. Let's keep up on forum housekeeping. ;-)

1
  • Thank you very much, you helped me a lot!
    – babaoriley
    May 2 '15 at 8:41

You must log in to answer this question.

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