Computer Science Canada

Exit Statement

Author:  Turing_Noob [ Sun May 10, 2009 5:20 pm ]
Post subject:  Exit Statement

how do you make an exit statement so that when q or Q is press then the loop will exit?

Author:  Dan [ Sun May 10, 2009 5:52 pm ]
Post subject:  Re: Exit Statement

Well the function for checking if a key is pressed is hasch.

And you can exit a loop with exit.

Author:  Turing_Noob [ Sun May 10, 2009 5:54 pm ]
Post subject:  RE:Exit Statement

i've already tried

exit when hasch(81)

but it says error, can you give me the could that would do that

Author:  Dan [ Sun May 10, 2009 6:06 pm ]
Post subject:  RE:Exit Statement

Sorry, i thought you wanted it to exit when any char was hit.

What you will have to do is use hasch to check if a key was hit and then check if it was equal to 'q' or 'Q' with getch or getchar.

It would be somthing like this:

code:

If there was a key hit then
    exit when the key is 'q' or 'Q'
end if


Note that is pesdocode.


Edit: Input.KeyDown will also work. See the example for Input.KeyDown in the turing documentation.

Author:  DanTheMan [ Thu May 14, 2009 11:17 am ]
Post subject:  RE:Exit Statement

if hasch "q" then
exit
end if

Author:  Dusk Eagle [ Thu May 14, 2009 2:00 pm ]
Post subject:  Re: Exit Statement

Dan, it's great that you're trying to help, but it helps no one when your code doesn't work. What Dan said above is probably the way to go.

Author:  BigBear [ Thu May 14, 2009 2:17 pm ]
Post subject:  RE:Exit Statement

You understand if you are getting input that it is hsch but you can't say if hasch "q"

you need to declare a string variable and get that variable then compare the vlue of that variable with "q" or "Q" You could look into getch aswell

(I pronounce it getch not get ch )

Author:  DanTheMan [ Fri May 15, 2009 8:26 am ]
Post subject:  Re: RE:Exit Statement

BigBear @ Thu May 14, 2009 2:17 pm wrote:
You understand if you are getting input that it is hsch but you can't say if hasch "q"

you need to declare a string variable and get that variable then compare the vlue of that variable with "q" or "Q" You could look into getch aswell

(I pronounce it getch not get ch )


Too right. That was my fault for leaving that out.


: