Quote: "Wasn't quite sure what you meant by the GOTO problem though, so could you explain that a little bit more in detail please.
EDIT: Sorry didn't see your code snippet there, that is why I posted my version down with some tweaks. Can see how you get away with not using the GOTOs now."
The main problem with GOTO is that it creates what we call Spaghetti Code (click on my signature to see the Wiki entry)... a jumbled up mess of code that's hard to track what's going on and debugging is a lot harder. GOTO forces you to use another GOTO to get back to the line you left. A better replacement is GOSUB. When you use GOSUB and you want go back to the line that sent you there use RETURN.
Your code with some changes using GOSUB instead of GOTO (with indenting to make it easier to read):
REMSTART Write a program that reads the size and position of 4 squares into a multidimensional array,
and draws the square specified. Once the square is drawn you should give the option to go back and select
another square or quit. REMEND
Dim A(4,4)
FOR X = 1 TO 4
FOR Y = 1 TO 4
READ A(X,Y)
NEXT Y
NEXT X
Do
CLS
Print "Press 1, 2, 3 or 4"
print ""
If keystate(2)=1 Then Y=1:Gosub DrawSquares
If keystate(3)=1 Then Y=2:Gosub DrawSquares
If keystate(4)=1 Then Y=3:Gosub DrawSquares
If keystate(5)=1 Then Y=4:Gosub DrawSquares
Loop
DrawSquares:
PRINT "Square ",Y
BOX A(Y,1), A(Y,2), A(Y,3), A(Y,4)
print "Press the returnkey if you wish to print another square or space to close"
Do
` Check for return and EXIT the loop
If keystate(28)=1 Then exit
` Check for spacebar and END the program
If keystate(57)=1 Then end
Loop
` Go back to the line under the GOSUB that called this routine
return
Data 20,20,50,50,60,60,100,100,100,100,150,150,200,200,300,300
Another replacement for GOTO are functions. They are the same as using GOSUB except they don't keep variables that aren't set as GLOBAL. Functions are nice to use because they can be sent specific variables/strings and return a variable/string too.
Your code with some changes using a function:
REMSTART Write a program that reads the size and position of 4 squares into a multidimensional array,
and draws the square specified. Once the square is drawn you should give the option to go back and select
another square or quit. REMEND
Dim A(4,4)
FOR X = 1 TO 4
FOR Y = 1 TO 4
READ A(X,Y)
NEXT Y
NEXT X
Do
CLS
Print "Press 1, 2, 3 or 4"
print ""
If keystate(2)=1 Then DrawSquares(1)
If keystate(3)=1 Then DrawSquares(2)
If keystate(4)=1 Then DrawSquares(3)
If keystate(5)=1 Then DrawSquares(4)
Loop
` Always put an END before the first function (just in case the unthinkable happens)
end
function DrawSquares(Y)
PRINT "Square ",Y
BOX A(Y,1), A(Y,2), A(Y,3), A(Y,4)
print "Press the returnkey if you wish to print another square or space to close"
Do
` Check for return and EXIT the loop
If keystate(28)=1 Then exit
` Check for spacebar and END the program
If keystate(57)=1 Then end
Loop
` Go back to the line under the function call
endfunction
Data 20,20,50,50,60,60,100,100,100,100,150,150,200,200,300,300
The way I believe is that we should learn about GOTO when we're newbies but after we learn about GOSUB and functions we should leave GOTO behind and never use it again.
Quote: "Will look at your tutorials later TDK, and will stop using the tutorial that I am using now lol."
Yeah, TDK's tutorials are top notch... read them all even if you think you know everything about a command.