0

i know a nested loop is needed, but when i declare GRect bricks, isn't the coordinates already set? how do i add length of brick to x each time it iterates??

i can technically make the bricks by doing

{ grect bricks= new grectbrick (x,y,height,width) set color set filled add window brick }

10 times. but thats not what they want. im quite confused as to how i would use a for loop to add (brick size) + (space) each time it runs

1

The coordinates are not already set. You need to write the code to supply the coordinates and the dimensions. Simply put, before you actually write the code, you need to figure out how many rows to create, how many bricks per row, how tall and wide each brick needs to be, how big a gap between each brick, both horizontally and vertically, how big a gap between the bricks and the sides of the window, and how big a gap between the top of the window and the top row of bricks. It's a lot of info, but each of these is needed to properly place all the bricks.

The for loops can deal with exactly where to place the bricks. Remember, in a FOR loop, the control variable doesn't have to start at 0 or 1, and it can be incremented by any amount, not just 1. For instance, it could start at 5 and increment by the width of a brick + the width of a gap. Similar thinking will cover many of the other values.

That should get you going.

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

You must log in to answer this question.

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