Computer Science Canada How to use loops with other loops?

 Author: Dogdemon [ Tue May 04, 2004 3:42 pm ] Post subject: How to use loops with other loops? sorry for posting another thread because no one seen to respond to me on my other thread anymore. my question is how can i use multiple loops for example if i had loop put "1" end loop loop put "2" end loop it only does the first one and in my program the first loop all the way at the bottom only works. setscreen ("graphics:1000;650") var font := Font.New ("serif:24") var fx : array 1 .. 10, 1 .. 10 of boolean var ax, bx : array 1 .. 11 of int var x, y, z, btx, bye, btn : int var key : string (1) for i : 1 .. 10 for j : 1 .. 10 fx (i, j) := false end for end for for i : 1 .. 10 ax (i) := 0 bx (i) := 0 end for for b : 1 .. 10 for a : 1 .. 10 %10 by 10 grid drawfillbox (90 + ax (a), 150 + bx (b), 140 + ax (a), 200 + bx (b), white) drawfillbox (95 + ax (a), 155 + bx (b), 140 + ax (a), 200 + bx (b), 7) drawbox (90 + ax (a), 150 + bx (b), 140 + ax (a), 200 + bx (b), 7) ax (a + 1) := a * 50 end for bx (b + 1) := b * 50 end for var beenhit : boolean loop mousewhere (x, y, z) if x >= 95 and x <= 140 and y >= 155 and y <= 200 and z = 1 then beenhit := true getch (key) Draw.Text (key, 105, 170, font, 10) else beenhit := false end if end loop loop mousewhere (x, y, z) if x >= 95 and x <= 140 and y >= 205 and y <= 250 and z = 1 then beenhit := true getch (key) Draw.Text (key, 105, 220, font, 10) else beenhit := false end if end loop

 Author: Paul [ Tue May 04, 2004 3:45 pm ] Post subject: lol ofcourse it only does the first one, it never exits the first one. How many times would u want to run it? or do u just want to go loop put "1" put "2" end loop

 Author: Dogdemon [ Tue May 04, 2004 3:57 pm ] Post subject: well what i mean is that i want to click my 2 boxes at any order let say 2nd loop first then i want that to exit and my other loop will work and when i click and press any letter i want that to exit and do it for my other boxes. so far i only have the bottom left corner box working and the one on top of it loop mousewhere (x, y, z) if x >= 95 and x <= 140 and y >= 155 and y <= 200 and z = 1 then beenhit := true getch (key) Draw.Text (key, 105, 170, font, 10) else beenhit := false exit when beenhit = true end if end loop loop mousewhere (x, y, z) if x >= 95 and x <= 140 and y >= 205 and y <= 250 and z = 1 then beenhit := true getch (key) Draw.Text (key, 105, 220, font, 10) else beenhit := false end if end loop

Author:  Cervantes [ Tue May 04, 2004 4:05 pm ]
Post subject:

anywho, theres an easier way to do what you're doing with that program. assuming your going to allow the user to input a value for each square, do this:

 code: setscreen ("graphics:1000;650") var font := Font.New ("serif:24") var fx : array 1 .. 10, 1 .. 10 of string var mx, my, mbtn : int var gridx, gridy : int var key : string (1) const gridsize := 50 const gridspace := 4 for i : 1 .. 10     for j : 1 .. 10         fx (i, j) := "-1"     end for end for for x : 1 .. 10     for y : 1 .. 10         drawfillbox (x * gridsize + gridspace, y * gridsize + gridspace, x * gridsize + gridsize, y * gridsize + gridsize, black)     end for end for loop     mousewhere (mx, my, mbtn)     if mbtn = 1 and whatdotcolour (mx, my) = black then         gridx := mx div gridsize         gridy := my div gridsize         getch (key)         fx (gridx, gridy) := key         Draw.Text (key, gridx * gridsize + (gridsize div 3), gridy * gridsize + (gridsize div 3), font, brightgreen)     end if end loop

EDIT: