Computer Science Canada the "Getch" procedure |
Author: | rcmp1234 [ Thu May 01, 2008 8:19 pm ] | ||
Post subject: | the "Getch" procedure | ||
*Note that menu is a procedure and has been declared before* Here I have a part of my program that asks the user to press a key. If the user presses e then he will be taken back to the menu. The problem is if he presses another letter the program will still keep on executing. Is there any way I can have the program wait for the user to press e (and does not continue executing if he presses another key)? I was thinking of putting it in a loop but you cant put a procedure in a loop ANd yes, I am a newbie in Turing Thanks! |
Author: | The_Bean [ Thu May 01, 2008 8:37 pm ] | ||
Post subject: | Re: the "Getch" procedure | ||
I just added in the "else" which means if it reply= anything but "e" then it does something else(what ever you might want it to be). But if you want the program to totally terminate if they put anything but "e", then work exit, return, or quit in there some how (depending on what the rest of your program is doing). |
Author: | TheGuardian001 [ Fri May 02, 2008 4:06 pm ] |
Post subject: | Re: the "Getch" procedure |
you could even use The_Bean's method to have the procedure call itself if they don't enter "e" |
Author: | Nick [ Fri May 02, 2008 4:08 pm ] | ||
Post subject: | RE:the "Getch" procedure | ||
or a loop inside the procedure
|
Author: | Tony [ Fri May 02, 2008 4:20 pm ] | ||
Post subject: | RE:the "Getch" procedure | ||
or call procedure after the loop
|
Author: | btiffin [ Fri May 02, 2008 5:16 pm ] |
Post subject: | Re: the "Getch" procedure |
These are all good answers so far. Do a google on Structured Programming for more info, but basically you want to use a DO ... UNTIL structure for that type of problem. DO get a key UNTIL key equals "e" Converting that to Turing will be left as an exercise. In purist terms, a LOOP IF ... RETURN ENDIF END LOOP is defined as a "hidden goto"; not horribly bad form, and quite acceptable now-a-days, but a DO ... UNTIL is just that little bit more structured, and usually more efficient, as there are no magical internal stack winds and unwinds or jumps going on behind the scenes. Cheers |
Author: | rcmp1234 [ Fri May 02, 2008 5:38 pm ] |
Post subject: | RE:the "Getch" procedure |
Thanks everyone...that did the trick! |
Author: | btiffin [ Fri May 02, 2008 5:39 pm ] |
Post subject: | Re: the "Getch" procedure |
My apologies to Tony. ![]() Cheers |