, | C, C++, JavaScript, Matlab, Perl, Pike, Prolog |
. | Smalltalk |
; | Ada, Awk, B, Beta, BourneShell, C, C#, C++, E, Haskell, Java, JavaScript, Maple, Matlab, merd, Modula-3, OCaml, Pascal, Perl, Perl6, PHP, Pike, PL/I, Pliant, Python, Ruby, SML, Tcl, YCP |
: | Maple |
nothing, optionally ; | Classic REXX, Lua |
space | Eiffel, Rebol |
end-of-line | Assembler, Awk, Basic, BourneShell, E, Fortran, Haskell, JavaScript, Lua, Matlab, merd, Pliant, Python, Ruby, Tcl |
(begin ...) | Scheme |
(progn ...) (prog1 ...) (prog2 ...) | Common Lisp, Emacs Lisp |
>> | Haskell |
if c then b | merd, OCaml, Pascal |
if c then b end | Eiffel, Lua, Oz, Ruby |
if c then b end if | Ada, Maple |
if c then b fi | Maple |
if c; then b; fi | BourneShell |
if (c) then b end | Dylan |
if c do b | BCPL |
IF c THEN b END | Modula-2, Modula-3 |
if (c) b | Awk, B, C, C#, C++, Java, JavaScript, PHP, Pike, YCP |
if c: b | Python |
if c b | Pliant, Rebol, Tcl |
if (c): b endif | PHP |
if c {b} | Perl6 |
if c [b] | Logo |
if (c) {b} | E, Perl, Yorick |
IF c b | MUMPS |
c -> b | FL |
c b if | PostScript |
b if c | Perl, Ruby |
c if b1 then | Forth |
(if c b) | Common Lisp, Scheme |
(when c b) | Emacs Lisp |
c ifTrue: b | Smalltalk |
<xsl:if test="c">b</xsl:if> | XSLT |
If c Then b | Visual Basic |
If c b End If |
Visual Basic |
if c; b end | Ruby |
if c, b, end | Matlab |
if c b end |
Matlab, Ruby |
if c then ; b if c then b if c then do b ... end |
Classic REXX |
if c then b1 else b2 | Haskell, merd, OCaml, SML |
if c then b1 else b2 end | Eiffel, Lua, Ruby |
if c then b1 elsif c2 then b2 else b3 end if | Ada |
if c then b1 elseif c2 then b2 else b3 end | Eiffel, Oz |
if (c) then b1 elseif (c2) then b2 else b3 end | Dylan |
IF c THEN b1 ELSIF c2 THEN b2 ELSE b3 END | Modula-3 |
If c Then b1 ElseIf c2 Then b2 Else b3 End If | Modula-2 |
if (c) b1 else b2 | Awk, B, C, C#, C++, Java, JavaScript, Pike, YCP |
if c ?then? b1 elsif c2 ?then? b2 ?else? b3 | Tcl |
if c then begin b1 end else begin b2 end | Pascal |
if c b1 eif c2 b2 else b3 | Pliant |
if c then b1 elif c2 then b2 else b3 end if | Maple |
if c; then b1; elif c2; then b2; else b3; fi | BourneShell |
if c1, b1, elseif c2, b2, else, b3, end | Matlab |
if (c) b1 elseif (c2) b2 else b3 | PHP |
if (c): b1 elseif (c2): b2 else: b3 endif | PHP |
if (c) {b1} elsif (c2) {b2} else {b3} | Perl |
if (c) {b1} else {b2} | E, Yorick |
(if c b1 b2) | Common Lisp, Scheme |
(if c then b1 else b2) | Mercury |
(c -> b1 ; c2 -> b2 ; b3) | Mercury |
c -> b1 ; b2 | FL |
c ifTrue: b1 ifFalse: b2 | Smalltalk |
ifelse c [b1] [b2] | Logo |
shunt c b1 c2 b2 b3 | Pliant |
either c b1 b2 / if/else c b1 b2 | Rebol |
(cond (c b1) (c2 b2) (t b3)) | Common Lisp, Emacs Lisp |
(cond (c b1) (c2 b2) (else b3)) | Scheme |
c -> b1 ; c2 -> b2 ; b3 | Prolog |
case when c; b1 when c2; b2 else b3 end | Ruby |
test c then b1 or b2 | BCPL |
e | c = b1 | c2 = b2 | otherwise = b3 | Haskell |
c b1 b2 ifelse | PostScript |
c if b1 else b2 then | Forth |
c ? b1 : b2 | Awk, B, C, C#, C++, Java, JavaScript, Perl, PHP, Ruby, YCP, Yorick |
c ?? b1 :: b2 | Perl6 |
b1 if c else b2 | Python |
$SELECT(c:b1,c2:b2,1:b3) | MUMPS |
c -> b1, b2 | BCPL |
(if c then b1 else b2 fi) | Beta |
<xsl:choose> <xsl:when test="c"> b1 </xsl:when> <xsl:when test="c2"> b2 </xsl:when> <xsl:otherwise> b3 </xsl:otherwise> </xsl:choose> |
XSLT |
If c Then b1 Else b2 | Visual Basic |
If c b1 Else b2 End If |
Visual Basic |
if c: b1 elif c2: b2 else: b3 |
Python |
if c b1 elsif c2 b2 else b3 end |
Ruby |
if c b1 elseif c2 b2 else b3 end |
Matlab |
if c then ; b1 ; else ; b2 if c then b1 else b2 if c then do b1 ... end else do b2 ... end |
Classic REXX |
IF c b ELSE b |
MUMPS |
unless | Emacs Lisp, Perl |
switch (val) { case v1: expr1; break; case v2: case v3: expr23; break; default: expr_else; } |
C, C++, Java, JavaScript, PHP, Pike |
switch val { case v1: expr1; goto done; case v2: case v3: expr23; goto done; } expr_else; done: |
B |
switch (val) { case v1: expr1; break; case v2: case v3: expr23; break; default: expr_else; break; } |
C# |
switch (val) { match v1 { expr1 } match v2 { expr2 } match _ { expr_else } } |
E |
switchon val case v1: expr1 case v2: expr2 default: expr_else |
BCPL |
switch val case v1 expr1 case {v2,v3} expr2 otherwise expr3 end |
Matlab |
case val of v1 : expr1; v2, v3 : expr23 else expr_else end |
Pascal |
case val in v1) statement1 ;; v2|v3) statement23 ;; *) statement_else ;; esac |
BourneShell |
(if val // v1 then expr1 // v2 then expr2 else expr_else if) |
Beta |
match val with | v1 -> expr1 | v2 | v3 -> expr23 | _ -> expr_else |
OCaml |
case val of v1 => expr1 | v2 => expr2 | _ => expr_else |
SML |
CASE val OF v1 => expr1 | v2 => expr2 ELSE => expr_else END |
Modula-3 |
case val of v1 -> expr1 v2 -> expr2 _ -> expr_else |
Haskell |
val. v1 -> expr1 v2 -> expr2 _ -> expr_else |
merd |
(case val ((v1) expr1) ((v2) expr2) (otherwise expr_else)) |
Common Lisp |
(case val ((v1) expr1) ((v2) expr2) (else expr_else)) |
Scheme |
case val is when v1 => expr1 when v2 | v3 => expr23 when others => expr_else end case; |
Ada |
case val when v1; expr1 when v2, v3; expr23 else expr_else end |
Ruby |
inspect val when v1 then statement1 when v2, v3 => statement23 else statement_else end |
Eiffel |
select (val); when (v1) statement1; when (v2, v3) statement23; otherwise statement_else; end; |
PL/I |
X = val, (X = v1, expr1 ; X = v2, expr2 ; expr_else) |
Mercury, Prolog |
my %case = ( v1 => sub { expr1 }, v2 => sub { expr2 }, ); if ($case{val}) { $case{val}->() } else { expr_else } |
Perl |
use Switch; switch ($val) { case v1 { expr1 } case v2 { expr2 } else expr_else }) |
Perl |
given $val { when v1 { expr1 } when v2 { expr2 } default { expr_else } } |
Perl6 |
Select val Case v1 expr1 Case v2, v3 expr2 Case Else expr_else End Select |
Visual Basic |
switch (val) { v1 { expr1 } v2 { expr2 } default { expr_else } } |
MSH |
switch val [ v1 [expr1] v2 [expr2] ] switch/default [ v1 [expr1] v2 [expr2] ][expr_else] |
Rebol |
val caseOf: {[v1]->[expr1]. [v2]->[expr2]} otherwise: expr_else | Squeak |
select when v1 expr1 when v2 | v3 expr23 otherwise expr_else end |
Classic REXX |
CASE val WHEN v1 THEN expr1 WHEN v2 THEN expr2 ELSE expr_else END |
SQL92 |
forever loop
loop | merd, PostScript, Ruby |
loop expr end loop | Ada |
LOOP expr END | Modula-3 |
(loop do expr) | Common Lisp |
cycle (# do ... #) | Beta |
repeat | Squeak |
forever | Logo, Rebol |
Do expr Loop |
Visual Basic |
do forever ... end |
Classic REXX |
while condition do something
while (cond) expr | Awk, B, C, C#, C++, E, Java, JavaScript, Perl, Perl6, PHP, Pike, Ruby, YCP, Yorick |
while cond expr | Tcl |
while cond loop expr end loop | Ada |
while cond do expr | BCPL, Pascal, SML |
while cond do expr done | OCaml |
while cond do expr end do | Maple |
WHILE cond DO expr end | Lua |
while cond: expr | Python |
while cond; do expr; done | BourneShell |
while cond, expr, end | Matlab |
while [cond][expr] | Rebol |
while cond [expr] | Logo |
do.while [expr] cond | Logo |
cond whileTrue: expr | Smalltalk |
(loop while cond do expr) | Common Lisp |
loop (# while ::< (# do cond -> value #) do expr #) | Beta |
begin cond while expr repeat | Forth |
from until not cond loop expr end | Eiffel |
while cond expr |
Pliant |
Do While cond expr Loop |
Visual Basic |
do while cond ... end |
Classic REXX |
do something until condition
do expr until cond | Perl6 |
do {expr} until cond | Perl |
do {expr} while (!cond) | Awk, C, C#, C++, Java, JavaScript, Pike, Yorick |
begin expr end until cond | Ruby |
REPEAT expr UNTIL cond | Modula-3 |
loop (# until ::< (# do cond -> value #) do expr #) | Beta |
loop expr exit when cond end loop | Ada |
(loop do expr until cond) | Common Lisp |
expr repeatuntil cond | BCPL |
repeat expr until cond | Lua, Pascal |
repeat expr until (cond) | YCP |
repeat, expr, cond | Prolog |
until [expr cond] | Rebol |
until cond [expr] | Logo |
do.while [expr] cond | Logo |
[expr . cond] whileFalse | Squeak |
Do expr Loop Until cond |
Visual Basic |
for each value in a numeric range, 1 increment (see also the entries about ranges)
for (int i = 1; i <= 10; i++) expr | C, C# |
foreach my $i (1 .. 10) { expr } | Perl |
foreach ($i in 1..10) { expr } | MSH |
for (1 .. 10) -> $i { expr } | Perl6 |
for i = 1:10, expr, end | Matlab |
for i := 1 to 10 do expr | Pascal |
for i = 1 to 10 do expr done | OCaml |
For i = 1 To 10 expr Next | Visual Basic |
for i in 1 .. 10 loop ... end loop | Ada |
for i in range(1, 11) | Python |
for i in `seq 1 10`; do expr; done | BourneShell |
FOR I=1:1:10 expr | MUMPS |
for i from 1 to 10 do expr end do | Maple |
for [i 1 10 +1] [expr] | Logo |
1 1 10 expr for | PostScript |
(1..10).each {|i| expr } | Ruby |
1.upto(10) {|i| expr } | Ruby |
do i = 1 for 10 ... end |
Classic REXX |
for each value in a numeric range, 1 decrement
for X := 10 downto 1 do expr | Pascal |
for i = 10 downto 1 do expr done | OCaml |
for i in reverse 1 .. 10 loop ... end loop | Ada |
for (int i = 10; i >= 1; i--) expr | C, C# |
for (my $i = 10; $i >= 1; $i--) { expr } | Perl |
loop (my $i = 10; $i >= 1; $i--) { expr } | Perl6 |
from i := 10 until i < 1 loop expr i := i - 1 end | Eiffel |
for i = 10:-1:1, expr, end | Matlab |
for i in range(10, 0, -1) | Python |
for i in `seq 10 -1 1`; do expr; done | BourneShell |
for i from 10 to 1 by -1 do expr end do | Maple |
for [i 1 10 -1] [expr] | Logo |
FOR I=10:-1:1 expr | MUMPS |
10 -1 1 expr for | PostScript |
10.downto(1) {|i| expr } | Ruby |
do i = 10 to 1 by -1 ... end |
Classic REXX |
for each value in a numeric range, free increment
for (int i = 1; i <= 10; i += 2) expr | C, C#, Pike |
for (i = 1; i <= 10; i += 2) expr | Awk |
for (my $i = 1; $i <= 10; $i += 2) { expr } | Perl |
loop (my $i = 1; $i <= 10; $i += 2) { expr } | Perl6 |
from i := 1 until i > 10 loop expr i := i + 2 end | Eiffel |
for i = 1:3:10, expr, end | Matlab |
for i in range(1, 11, 2) | Python |
for ((x = 1; x <= 10; x += 2)); do ...; done | BourneShell |
for i from 1 to 10 by 2 do expr end do | Maple |
for [i 1 10 2] [expr] | Logo |
FOR I=1:2:10 expr | MUMPS |
1 2 10 expr for | PostScript |
(1..10).step(2) {|i| expr } | Ruby |
do i = 1 to 10 by 2 ... end |
Classic REXX |
for "a la C" (while + initialisation)
for | Awk, C, C#, C++, Java, JavaScript, MSH, Perl, PHP, Pike, Tcl, Yorick |
loop | Perl6 |
for ((x = 0; x < 10; x++)); do ...; done | BourneShell |
from init_code until cond loop ... incr_statement end | Eiffel |
returning a value
return | Ada, Awk, B, BCPL, BourneShell, C, C#, C++, Classic REXX, Common Lisp, E, Java, JavaScript, Lua, Maple, Matlab, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Tcl, YCP, Yorick |
Return | Visual Basic |
RETURN | Modula-3 |
resultis | BCPL |
return from xxx | Common Lisp |
^ | Smalltalk |
Exit Function / Exit Sub | Visual Basic |
output | Logo |
goto (unconditional jump)
goto | Ada, B, Basic, BCPL, C, C#, C++, Cobol, Fortran, Logo, MUMPS, Pascal, Perl, Yorick |
go throw | Common Lisp |
signal | Classic REXX |
continue / break
continue / break | Awk, C, C#, C++, E, Java, JavaScript, Matlab, PHP, Pike, Python, YCP, Yorick |
next / last | Perl, Perl6 |
next / break | Maple, Ruby |
/ break | BCPL, Lua |
/ break/return | Rebol |
/ exit | Ada, PostScript |
/ stop | Logo |
restart / leave | Beta, Pliant |
/ Exit Do, Exit For | Visual Basic |
/ return from xxx or return | Common Lisp |
iterate / leave | Classic REXX |
redo / retry
redo/ | Perl, Perl6 |
redo / retry | Ruby |
throwing
raise | Ada, Eiffel, merd, OCaml, Python, Ruby, Scheme-SRFI34, SML |
RAISE | Modula-3 |
raise ... end | Oz |
throw | C#, C++, E, Erlang, Haskell, Java, JavaScript, Logo, Pike, Prolog, Rebol |
throw/name | Rebol |
die | Perl, Perl6 |
return -code | Tcl |
error | Common Lisp, Dylan, Emacs Lisp, Lua, Lua, Maple, Matlab, Pliant |
signal | Common Lisp, Dylan, Smalltalk |
signal predefined_condition_name | Classic REXX |
cerror warn | Common Lisp |
[NSException raise:name ...] | Objective-C |
catching
try: a except exn: b | Python |
try a with exn -> b | OCaml |
try a catch (exn) b | C#, C++, Java, JavaScript |
try a catch exn then b end | Oz |
try a catch exn: b end try | Maple |
try { a CATCH exn { b } } | Perl6 |
TRY a EXCEPT exn => b END | Modula-3 |
a handle exn => b | SML |
a on: exception_name do: [:exn | b] | Smalltalk |
ifCurtailed | Smalltalk |
rescue | Eiffel, Ruby |
eval {a}; if ($@) b | Perl |
exception when exception_name => | Ada |
catch a (\exn -> b) | Haskell |
catch | Erlang, Logo, Prolog, Rebol, Tcl |
catch/name | Rebol |
catch(expr) or catch { ... }; | Pike |
pcall | Lua |
with-exception-handler or guard | Scheme-SRFI34 |
block a exception(exn) b end | Dylan |
?, shy, safe | Pliant |
handler-bind handler-case ignore-errors | Common Lisp |
NS_DURING a NS_HANDLER b NS_ENDHANDLER | Objective-C |
try a catch b end |
Matlab |
signal on predefined_condition_name ... predefined_condition_name : ... |
Classic REXX |
cleanup: code executed before leaving
ensure | Ruby, Smalltalk |
finally | C#, Java, Maple, Python |
FINALLY | Modula-3 |
unwind-protect | Common Lisp, Emacs Lisp |
cleanup | Dylan |
dynamic-wind | Scheme |
retrying: after catching an exception, tell the snippet to be re-run
retry | Eiffel, Ruby, Smalltalk |
restart | Dylan |
continue | Python |
resume execution where the exception took place
resume | Smalltalk |
call-with-current-continuation | Scheme |
callcc | Ruby, SML-NJ |