Program termination: Difference between revisions
Content added Content deleted
(Created task with Java and BASIC) |
(added c, ocaml, perl, python) |
||
Line 6: | Line 6: | ||
end |
end |
||
end if</qbasic> |
end if</qbasic> |
||
=={{header|C}}== |
|||
<c>#include <stdlib.h> |
|||
if(problem){ |
|||
exit(integerErrorCode); /*conventionally, error code 0 is the code for "OK", while anything else is an actual problem*/ |
|||
/*optionally: return the integerErrorCode from the main() function*/ |
|||
}</c> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
Line 12: | Line 20: | ||
//optionally: Runtime.getRuntime().exit(integerErrorCode); |
//optionally: Runtime.getRuntime().exit(integerErrorCode); |
||
}</java> |
}</java> |
||
=={{header|OCaml}}== |
|||
<ocaml>if problem then |
|||
exit integerErrorCode (*conventionally, error code 0 is the code for "OK",while anything else is an actual problem*)</ocaml> |
|||
=={{header|Perl}}== |
|||
<perl>if ($problem) { |
|||
exit integerErrorCode; #conventionally, error code 0 is the code for "OK" (you can also omit the argument in this case) |
|||
#while anything else is an actual problem |
|||
}</perl> |
|||
=={{header|Python}}== |
|||
<python>if problem: |
|||
sys.exit(integerErrorCode) #conventionally, error code 0 is the code for "OK" (you can also omit the argument in this case) |
|||
#while anything else is an actual problem</python> |
Revision as of 22:45, 21 April 2008
Program termination
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Show the syntax for a complete stoppage of a program inside a conditional. This includes all threads/processes running under your program.
BASIC
<qbasic>if problem = 1 then
end
end if</qbasic>
C
<c>#include <stdlib.h>
if(problem){
exit(integerErrorCode); /*conventionally, error code 0 is the code for "OK", while anything else is an actual problem*/ /*optionally: return the integerErrorCode from the main() function*/
}</c>
Java
<java>if(problem){
System.exit(integerErrorCode); //conventionally, error code 0 is the code for "OK", while anything else is an actual problem //optionally: Runtime.getRuntime().exit(integerErrorCode);
}</java>
OCaml
<ocaml>if problem then
exit integerErrorCode (*conventionally, error code 0 is the code for "OK",while anything else is an actual problem*)</ocaml>
Perl
<perl>if ($problem) {
exit integerErrorCode; #conventionally, error code 0 is the code for "OK" (you can also omit the argument in this case) #while anything else is an actual problem
}</perl>
Python
<python>if problem:
sys.exit(integerErrorCode) #conventionally, error code 0 is the code for "OK" (you can also omit the argument in this case) #while anything else is an actual problem</python>