Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to use loops with other loops?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Dogdemon




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Tue May 04, 2004 3:45 pm   Post subject: (No 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
Dogdemon




PostPosted: Tue May 04, 2004 3:57 pm   Post subject: (No 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
Cervantes




PostPosted: Tue May 04, 2004 4:05 pm   Post subject: (No subject)

wow, 2D arrays of boolean and your asking this questions? odd.
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:
just read your post now. to answer your question about switching between loops like that...


code:

loop

loop
stuff
exit when click
end loop

loop
other stuff
exit when click
end loop

end loop

that will cycle between the loops whenever the button is clicked.
Dogdemon




PostPosted: Tue May 04, 2004 4:10 pm   Post subject: (No subject)

hey thanx for the help.

o yea and i had help with my program with a student from my class ><
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: