Program termination

From Rosetta Code
Revision as of 22:45, 21 April 2008 by rosettacode>Spoon! (added c, ocaml, perl, python)
Task
Program termination
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

Works with: QuickBasic version 4.5

<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>