Computer Science Canada

how to end a program

Author:  musicman [ Mon May 03, 2010 11:56 am ]
Post subject:  how to end a program

procedure battle
enemychoose
loop
put "What do you wish to do?"
put "Fight?"
put "Heal?"
put "Flee?"
get answer
if answer = "fight" then
put "Which weapon would you like to use?"
put primaryname, "?"
put secondaryname, "?"
put meleename, "?"
elsif answer = "heal" then
health := health + healRate
elsif answer = "flee" then
else
put "Invalid response"
end if
end loop
end battle

Author:  USEC_OFFICER [ Mon May 03, 2010 12:03 pm ]
Post subject:  RE:how to end a program

What are you trying to do?

Author:  Zren [ Mon May 03, 2010 12:13 pm ]
Post subject:  Re: how to end a program

If your wondering how to exit loops.

Turing:

loop
    exit
end loop

var running :boolean := true
loop
    exit when running = false
end loop


First one will exit straightaway while the second will cause an infinite loop without modifying the variable running inside the loop.

Oh and from now on please wrap your code in:
code:
[syntax="turing"][/syntax]

Makes things easier to see and allows for indentation to show.

Author:  musicman [ Mon May 03, 2010 9:52 pm ]
Post subject:  Re: how to end a program

gdi...there was suppossed to be more to that post. i know how to exit loops, what i wanted to know is how to exit a program altogether even if it is in the middle of it, for instances such as deaths in games.

Author:  TheGuardian001 [ Mon May 03, 2010 10:31 pm ]
Post subject:  Re: how to end a program

well, that depends on how your program is structured.

If you're using loops, then you can just exit out of all your loops, such that the program reaches the end of the file.

If your game is within a procedure, you can use return to get out of that procedure, which will allow you to reach the end of the file.

Or, if you just want something that will stop the program dead in its tracks, you can use quit, which simply kills the execution of the program altogether.

Author:  musicman [ Tue May 04, 2010 8:25 am ]
Post subject:  Re: how to end a program

i was just looking for a command to kill the program altogether, so the quit command is the one im lookin for, thanks

Author:  BigBear [ Tue May 04, 2010 3:13 pm ]
Post subject:  RE:how to end a program

quit is basically used like an assert statement it is for development purposes.

your program ends when it runs out of code so it starts at the first line and goes through your code will it gets to the bottom last line.

if you have a loop it will go back to the top of that loop forever unless you exit the loop so to end you exit all loops procedures etc

Author:  TheGuardian001 [ Tue May 04, 2010 3:49 pm ]
Post subject:  Re: how to end a program

It may be intended for debug purposes, but it will stop the program, even in compiled form. Of course, it brings up an error message, but it does kill the program.

I suppose I should mention that it is by no means the correct way to end a program. The correct way is to return out of whatever procedure you are in and exit any loops until you reach the end of your code.


: