perhaps this helps to explain it
rem the syncs live at the very top they dont live in main
sync on : sync rate 40
rem this do /loop combo is ok but use a while/endwhile
rem so you can exit it at any time
rem this while endwhile over writes the escapekey
rem and exits when you press it
disable escapekey
while escapekey()=0
rem check for user input first
mousex=mousex()
mousey=mousey()
mousez=mousez()
if upkey()=1 then shipy=shipy+1
if downkey()=1 then shipy=shipy-1
if leftkey()=1 then shipx=shipx-1
if rightkey()=1 then shipx=shipx+1
if spacekey()=1 then hp=hp-1
if hp=0 then hp=100
rem update all objects after u have requested
rem the players controls
text 550,410,str$(misslecount)
stretch sprite 3,hp,100
sprite 1,mousex,mousey,3
position object 1,shipx,shipy,shipz
rem adding the sync at the end of the main loop updates
rem or refreshes the screen here, after the controls and updates.
sync
rem closing the endwhile condition
endwhile
rem here is where you should delete images models sounds
and undim arrays
rem finally using an end to end your program
this is untested but it should work as is.