Program termination: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(11 intermediate revisions by 8 users not shown)
Line 392:
<syntaxhighlight lang="bbcbasic">_@</syntaxhighlight>
The @ instruction ends the program. Some interpreters revert changes to the code (made by p) while others do not.
 
=={{header|BQN}}==
<code>•Exit</code> immediately terminates the running BQN process. If the argument is a valid return code (on Unix, an integer), it is returned; otherwise, the default return code (the one returned when the end of the program is reached) is used.
 
We can use a block to create a conditional exit. Here we exit if the script is given zero command line arguments:
<syntaxhighlight lang="bqn">{
0=≠•args ? •Exit 0;
•Show "has args"
}</syntaxhighlight>
 
=={{header|Bracmat}}==
Line 607 ⟶ 616:
or
<syntaxhighlight lang="delphi">System.Halt(1); // Optional exit code</syntaxhighlight>
 
=={{header|dt}}==
<syntaxhighlight lang="dt">[quit] true do?</syntaxhighlight>
 
=={{header|E}}==
Line 633 ⟶ 645:
 
Functions in <code>kill-emacs-hook</code> are called. (Except prior to Emacs 24 that hook was not run when in <code>-batch</code> mode.) The underlying C library <code>atexit()</code> handlers are called.
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
^| I try to use the exit codes described at:
| https://github.com/openbsd/src/blob/master/include/sysexits.h
|^
int EX_SOFTWARE = 70 # internal software error
logic hasProblem = true
if hasProblem do exit EX_SOFTWARE end
</syntaxhighlight>
{{out}}
<pre>
emal.exe Org\RosettaCode\ProgramTermination.emal
echo Exit Code is %errorlevel%
Exit Code is 70
</pre>
 
=={{header|Erlang}}==
Line 708 ⟶ 736:
exit code is 1
</pre>
 
=={{header|FutureBasic}}==
Quick and dirty. Terminates everything.
<syntaxhighlight lang="futurebasic">
if condition then end
</syntaxhighlight>
 
=={{header|Gambas}}==
Line 948 ⟶ 982:
<syntaxhighlight lang="javascript">if (some_condition)
quit();</syntaxhighlight>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">[true] [quit] [] ifte.</syntaxhighlight>
 
=={{header|jq}}==
Line 1,357 ⟶ 1,394:
if problem:
os.abort()</syntaxhighlight>
 
=={{header|Quackery}}==
 
<code>out!</code> will cleanly exit Quackery and return control to the calling program. This is demonstrated in the Quackery shell. When <code>10 random</code> returns <code>0</code> Quackery (which in this implementation is a function called from Python3) returns control to Python, which then terminates in the usual fashion and returns control to the zsh, from which we show this to be the case and then re-enter Quackery.
 
<syntaxhighlight lang="Quackery"> [ return$ nest$ size 2 / ]bailby[ ] is out! ( --> )</syntaxhighlight>
 
{{out}}
 
<pre>/O> [ 10 random dup
... iff
... [ echo cr ]
... else
... [ say "Bye-ee!" cr
... drop out! ]
... again ]
...
5
2
5
Bye-ee!
$ echo "$SHELL"
/bin/zsh
$ quackery
 
Welcome to Quackery
 
Enter "leave" to leave the shell.
 
Building extensions.
 
/O> </pre>
 
=={{header|QB64}}==
Line 1,470 ⟶ 1,539:
next
</syntaxhighlight>
 
=={{header|RPL}}==
There are 2 ways of terminating a program in RPL.
'''IF''' problem '''THEN''' HALT '''END'''
Here, nothing is cleaned up: local variables are still existing and a step-by-step execution is possible thanks to the <code>SST</code> instruction, typically for debugging. Once the bug found, a manual cleanup must be done through the <code>KILL</code> instruction.
If a full termination with cleanup is desired, it must be written:
'''IF''' problem '''THEN''' ABORT '''END'''
All currently running processes are then terminated, all local variables are discarded and control is given back to the user.
 
=={{header|Ruby}}==
Line 1,742 ⟶ 1,819:
'...
End Sub</syntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">
for num in 1..10 {
println('$num')
if num == 5 {exit(1)}
}
</syntaxhighlight>
 
{{out}}
<pre>
Process started >>>
1
2
3
4
5
<<< Process finished (Exit code 1)
</pre>
 
=={{header|Wren}}==
Line 1,757 ⟶ 1,853:
 
The following example illustrates the use of Fiber.suspend in a Wren CLI script.
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
 
System.write("Do you want to terminate the program y/n ? ")
Line 1,770 ⟶ 1,866:
{{out}}
<pre>
$ wren_cli program_terminationProgram_termination.wren
Do you want to terminate the program y/n ? y
OK, shutting down
9,476

edits