Here's the thing, a do/loop (everything in between those two words) means that every frame, the program will do everything between those two words.
That means that if you have:
Then every single frame, (tiny bit of program time) it will do the bit between the do/loop. In this case, it will print "Hello" on the next line. This isn't good, in our case as it'll spam off the bottom of the page in a big line.
You need to learn about three things:
cls - cls on its own, or with a colour (like "cls rgb(255,0,0)") will clean the screen of everything to one colour. By default that is black, but in the colour example, it would be red. (255 in the red channel, and 0 in green and blue).
set cursor 0,0 - this will put your 'print' cursor somewhere on the screen - in this example at X=0 and Y=0, which is the very top left of the screen. Using this in our do/loop would stop the Prints from scrolling off the bottom of the screen.
variables - not a command, but a very important part of programming. What you want to do is store the state of your printing. I.e. if you had pressed F1 once, you want to print stuff, and if you press it again, you want to stop printing stuff. That's a state (print or not) - we could use '1' as 'we want to print' and '0' as 'no print'. We put this in a variable - just a name that we keep numbers in.
So, enough theory - here's a bit of code that should demonstrate this in action:
`Sync means "update the screen" - we want to update the screen.
sync on
`This means that if the computer is fast enough, run through the loop 60 times a second.
sync rate 60
`Our variable for printing. More descriptive names SO help in the long run.
Welcome$ = "Hello World!"
`Start of our do/loop. Everything in here happens many times a second (60).
do
`Clean the screen every loop.
cls
`position the printing cursor in the top left - play with these numbers if you like.
set cursor 0,0
`Every loop, print out the instructions.
print "Press (and hold) F1 to say hello."
`Check to see if F1 is pressed.
if keystate(59) = 1
print Welcome$
endif
`Note, we don't need to check to see if we're NOT pressing F1
`Because if we're not pressing it, it never gets printed and
`the screen stays black from the 'cls'.
`This commant tells the program to update the screen!
sync
loop
Hope that helps.