Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
How to use loops with other loops?
Author Message
Dogdemon

Posted: 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

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

Paul

Posted: 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

Posted: 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

Posted: Tue May 04, 2004 4:05 pm   Post subject: (No 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:

 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

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: