Posts: 2
Threads: 2
Joined: Jun 2003
hi everyone, i am new around here. istarted about a day ago. my problem is that i cannot get things to move in qbasic. there is always an error message like loop without do. but there is do in the program. i need help. anybody has any suggestions or help for me should please send it to me. :???:
Posts: 2,020
Threads: 24
Joined: Jun 2002
Well, If it's telling you loop without do, that can also mean there's an unclosed loop inside. check all your FOR...NEXTs, WHILE...WENDs, IF...END IFs, and DO...LOOPs, and make sure they're all closed off, and nested. If they're not nested, eg.
Code:
DO
FOR x = 1 to 10
LOOP
NEXT
this will cause an error as well.
Post your source code, and I can give you more specific help.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Posts: 358
Threads: 15
Joined: May 2003
Your question might have been preferablly asked in the "newbie help" forum.
Here are 2 simple programs that move a circle. the first bounces it back and forth across the screen. the second one gives the user control using the number keypad.
Code:
'This simple program demonstrates 1 way of moving objects on screen using
'DO LOOP and FOR NEXT loop structures
DEFINT A-Z
delay = 10 'slows as cube of this number
y = 240 'constants used to abstract drawing functions
radius = 20
black = 0
xdirection = 1
ydirection = 0 'not used...motion only in 1-D
xbeg = radius
xend = 639 - radius
delay = ABS(delay) 'just in case...
SCREEN 11
CLS
PRINT "Press any key to stop"
DO
FOR x = xbeg TO xend STEP xdirection
CIRCLE (x - xdirection, y - ydirection), radius, black 'erase previously drawn circle
CIRCLE (x, y), radius, NOT black 'draw new circle
FOR p = 0 TO delay: FOR pa = 0 TO delay: FOR pb = 0 TO delay 'delay loops
IF INKEY$ <> "" THEN END 'check for keypress
NEXT pb, pa, p
NEXT x
SWAP xbeg, xend
xdirection = xdirection * -1
LOOP
END
Code:
SCREEN 11
r = 10
x = 320
y = 240
delta = 10
CLS
PRINT "Wow...I can move a circle...use 2, 4, 6, & 8 on the number pad"
PRINT "(make sure num-lock is on)"
DO
CIRCLE (oldx, oldy), r, 0
CIRCLE (x, y), r, 1
DO
a$ = INKEY$
LOOP UNTIL a$ <> ""
oldx = x
oldy = y
SELECT CASE a$
CASE "2"
y = y + delta
CASE "4"
x = x - delta
CASE "8"
y = y - delta
CASE "6"
x = x + delta
END SELECT
LOOP
Hope this helps