| if | else if | select case | conditional expression |
---|
Ada | if condition then statements«else statements»end if | if condition1 then statementselsif condition2 then statements...«else statements»end if | case expression is when value_list1 => statements when value_list2 => statements ... «when others => statements»end case | (if condition1 then expression1«elsif condition2 then expression2»...else expressionn)or(case expression is when value_list1 => expression1 when value_list2 => expression2 ... «when others => expressionn») |
Seed7 | if condition then statements«else statements»end if | if condition1 then statementselsif condition2 then statements...«else statements»end if | case expression of when set1 : statements ... «otherwise: statements»end case | |
Modula-2 | if condition then statements«else statements»end | if condition1 then statementselsif condition2 then statements...«else statements»end | case expression of caseLabelList : statements | ... «else statements»end | |
ALGOL 68 | if condition then statements «else statements» fi | if condition then statements elif condition then statements fi | case switch in statements, statements«,... out statements» esac | ( condition | valueIfTrue | valueIfFalse ) |
ALGOL 68(brief form) | ( condition | statements «| statements» ) | ( condition | statements |: condition | statements ) | ( variable | statements,... «| statements» ) | |
APL | :If condition instructions«:Else instructions»:EndIf | :If condition instructions:ElseIf condition instructions...«:Else instructions»:EndIf | :Select expression :Case case1 instructions ... «:Else instructions»:EndSelect | {condition:valueIfTrue ⋄ valueIfFalse} |
C (C99) | if (condition) instructions«else instructions»instructions can be a single statement or a block in the form of: { statements } | if (condition) instructionselse if (condition) instructions...«else instructions»orif (condition) instructionselse { if (condition) instructions } | switch (variable) { case case1: instructions «; break;» ... «default: instructions»} | condition ? valueIfTrue : valueIfFalse |
Objective-C |
C++ (STL) |
D |
Java |
JavaScript |
PHP |
C# | if (condition) instructions«else instructions» instructions can be a single statement or a block in the form of: { statements } | if (condition) instructionselse if (condition) instructions...«else instructions» | switch (variable){ case case1: instructions «break_or_jump_statement» ... «default: instructions break_or_jump_statement»} All non-empty cases must end with a break or goto case statement (that is, they are not allowed to fall-through to the next case).The default case is not required to come last. | condition ? valueIfTrue : valueIfFalse |
Windows PowerShell | if (condition) instruction«else instructions» | if (condition) { instructions }elseif (condition) { instructions }...«else { instructions }» | switch (variable) { case1{instructions «break;» } ... «default { instructions }»} | |
Go | if condition {instructions}«else {instructions}» | if condition {instructions}else if condition {instructions}...«else {instructions}»orswitch { case condition: instructions ... «default: instructions»} | switch variable { case case1: instructions ... «default: instructions»} | |
Swift | if condition {instructions}«else {instructions}» | if condition {instructions}else if condition {instructions}...«else {instructions}» | switch variable { case case1: instructions ... «default: instructions»} | |
Perl | if (condition) {instructions}«else {instructions}»orunless (notcondition) {instructions}«else {instructions}» | if (condition) {instructions}elsif (condition) {instructions}...«else {instructions}»orunless (notcondition) {instructions}elsif (condition) {instructions}...«else {instructions}» | use feature "switch";...given (variable) { when (case1) { instructions } ... «default { instructions }»} | condition ? valueIfTrue : valueIfFalse |
Raku | if condition {instructions}«else {instructions}»orunless notcondition {instructions} | if condition {instructions}elsif condition {instructions}...«else {instructions} | given variable { when case1 { instructions } ... «default { instructions }»} | condition ?? valueIfTrue !! valueIfFalse |
Ruby | if condition instructions«else instructions» | if condition instructionselsif condition instructions...«else instructions»end | case variable when case1 instructions ... «else instructions»end | condition ? valueIfTrue : valueIfFalse |
Scala | if (condition) {instructions}«else {instructions}» | if (condition) {instructions}else if (condition) {instructions}...«else {instructions}» | expression match { case pattern1 => expression case pattern2 => expression ... «case _ => expression»}[b] | if (condition) valueIfTrue else valueIfFalse |
Smalltalk | condition ifTrue: trueBlock«ifFalse: falseBlock»end | | | condition ifTrue: trueBlock ifFalse: falseBlock |
Common Lisp | (when condition instructions)or(unless condition instructions)or(if condition (progn instructions) «(progn instructions)») | (cond (condition1 instructions) (condition2 instructions) ... «(t instructions)») | (case expression (case1 instructions) (case2 instructions) ... «(otherwise instructions)») | (if test then else)or(cond (test1 value1) (test2 value2) ...)) |
Scheme | (when condition instructions)or(if condition (begin instructions) «(begin instructions)») | (cond (condition1 instructions) (condition2 instructions) ... «(else instructions)») | (case (variable) ((case1) instructions) ((case2) instructions) ... «(else instructions)») | (if condition valueIfTrue valueIfFalse) |
ISLISP | (if condition (progn instructions) «(progn instructions)») | (cond (condition1 instructions) (condition2 instructions) ... «(t instructions)») | (case expression (case1 instructions) (case2 instructions) ... «(t instructions)») | (if condition valueIfTrue valueIfFalse) |
Pascal | if condition then begin instructionsend«else begin instructionsend»'[c] | if condition then begin instructionsendelse if condition then begin instructionsend...«else begin instructionsend»[c] | case variable of case1: instructions ... «else: instructions»end[c] |
Visual Basic | If condition Then instructions«Else instructions»End IfSingle-line, when instructions are instruction1 : instruction2 : ...:If condition Then instructions «Else instructions» | If condition Then instructionsElseIf condition Then instructions...«Else instructions»End IfSingle-line:See note about C-like languages; the Else clause of a single-line If statement can contain another single-line If statement. | Select« Case» variable Case case_pattern1 instructions ... «Case Else instructions»End Select | IIf(condition, valueIfTrue, valueIfFalse) |
Visual Basic .NET | If(condition, valueIfTrue, valueIfFalse) |
Xojo |
Python[a] | if condition :Tab ↹instructions«else:Tab ↹instructions» | if condition :Tab ↹instructionselif condition :Tab ↹instructions...«else:Tab ↹instructions» | Python 3.10+:match variable:Tab ↹case case1:Tab ↹Tab ↹instructionsTab ↹case case2:Tab ↹Tab ↹instructions | Python 2.5+:valueIfTrue if condition else valueIfFalse |
S-Lang | if (condition) { instructions } «else { instructions }» | if (condition) { instructions } else if (condition) { instructions } ... «else { instructions }» | switch (variable) { case case1: instructions } { case case2: instructions } ... | |
Fortran | IF (condition) THEN instructionsELSE instructionsENDIF | IF (condition) THEN instructionsELSEIF (condition) THEN instructions...ELSE instructionsENDIF | SELECT CASE(variable) CASE (case1) instructions ... CASE DEFAULT instructionsEND SELECT | |
Forth | condition IF instructions « ELSE instructions» THEN | condition IF instructions ELSE condition IF instructions THEN THEN | value CASE case OF instructions ENDOF case OF instructions ENDOF default instructionsENDCASE | condition IF valueIfTrue ELSE valueIfFalse THEN |
OCaml | if condition then begin instructions end «else begin instructions end» | if condition then begin instructions end else if condition then begin instructions end ... «else begin instructions end» | match value with pattern1 -> expression | pattern2 -> expression ... «| _ -> expression»[b] | if condition then valueIfTrue else valueIfFalse |
F# | Lightweight syntax mode: Either on a single line or with indentation as shown below:if condition thenTab ↹instructions«elseTab ↹instructions»Verbose syntax mode:Same as Standard ML. | Lightweight syntax mode:Either on a single line or with indentation as shown below:if condition thenTab ↹instructionselif condition thenTab ↹instructions...«elseTab ↹instructions»Verbose syntax mode:Same as Standard ML. |
Standard ML | if condition then «(»instructions «)»else «(» instructions «)» | if condition then «(»instructions «)»else if condition then «(» instructions «)»...else «(» instructions «)» | case value of pattern1 => expression | pattern2 => expression ... «| _ => expression»[b] |
Haskell (GHC) | if condition then expression else expressionorwhen condition (do instructions)orunless notcondition (do instructions) | result | condition = expression | condition = expression | otherwise = expression | case value of { pattern1 -> expression; pattern2 -> expression; ... «_ -> expression»}[b] |
Bash shell | if condition-command; then expression«else expression»fi | if condition-command; then expressionelif condition-command; then expression«else expression»fi | case "$variable" in "$condition1" ) command... "$condition2" ) command...esac | |
CoffeeScript | if condition then expression «else expression»orif condition expression«else expression»orexpression if conditionorunless condition expression«else expression»orexpression unless condition | if condition then expression else if condition then expression «else expression»orif condition expressionelse if condition expression«else expression»orunless condition expressionelse unless condition expression«else expression» | switch expression when condition then expression else expressionorswitch expression when condition expression «else expression» | All conditions are expressions. |
COBOL | IF condition «THEN» expression«ELSE expression».[d] | | EVALUATE expression «ALSO expression...» WHEN case-or-condition «ALSO case-or-condition...» expression ... «WHEN OTHER expression»END-EVALUATE | |
Rust | if condition { expression}« else { expression}» | if condition { expression} else if condition { expression}« else { expression}» | match variable { pattern1 => expression, pattern2 => expression, pattern3 => expression, «_ => expression»}[b][e] | All conditions are expressions |
| if | else if | select case | conditional expression |
---|