
-----------------------------------
BlackCoyote
Thu Jan 24, 2019 5:55 pm

How to exit in a case?
-----------------------------------
Alright, so I am working on a project for school. It requires a menu in order to select what you  would like, the third option has to be exit, but I can't seem to figure out what needs to go here to exit the case, and in turn, exit the program, as the user said exit. How would I go about doing something like this? Also, when I input my choices using a string, it says that the case alternative label is the wrong type

Thanks in advance for helping in anyway you can. :)

~BlackCoyote

Turing version 4.1.1


Sample Code:
var Choice: string(1)
put "":33, "Stoplight Menu"
put ""
put ""
put ""
put "Please select one of the following choices"
put ""
put "":33, "1 - Intersection"
put ""
put "":33, "2 - Light Show"
put ""
put "":33, "3 - Exit"
put ""
getch (Choice)

case Choice of
    label 1 : 
    Int_Sub
    label 2 : 
    Light_Show
    label 3 : 
    exit
    label :
    put "Invalid, please reselect"
end case

-----------------------------------
Insectoid
Fri Jan 25, 2019 2:30 am

RE:How to exit in a case?
-----------------------------------
You have two options. You can use the quit keyword, which will terminate the program immediately, or you can have that case do nothing, and simply let the program run out of code.

-----------------------------------
scholarlytutor
Mon Jul 15, 2019 7:00 pm

RE:How to exit in a case?
-----------------------------------
For anyone who comes with the same problem, I make these menus pretty often and always structure them this way:

Before you start the case, begin a loop by typing "loop" (without the quote marks, of course).

Write "end loop" after the case is finished.

Now, your program will be able to use the "exit" command. Also, an added advantage is that the user can choose multiple options before deciding to exit the program.
