If ... else examples and documentation links in different programming languages.
The examples cover a blackjack scenario and a deep link to the reference documentation of the programming languages.
See wiki article Conditional Programming for general information about conditional statements.
The if ... else syntax is also known as "if statement", "conditional statements", "compound statements", "if else structure" or "conditional constructs".
XSLT<xsl:choose> <xsl:when test="card > 21"> busted </xsl:when> <xsl:when test="card = 21"> won </xsl:when> <xsl:otherwise"> continue </xsl:otherwise> </xsl:choose> |
Java
if (card > 21) {
System.out.println("busted");
} else if (card == 21) {
System.out.println("won");
} else {
System.out.println("continue");
}
|
PHP
if ($card > 21) {
echo "busted";
} else if ($card == 21) {
echo "won";
} else {
echo "continue";
}
|
Perl
if ($card > 21) {
print "busted";
} elseif ($card == 21) {
print "won";
} else {
print "continue";
}
|
Pythonif card > 21: print "busted" elif card == 21: print "won" else: print "continue" |
C, C++, Objective-C
if (card > 21) {
printf("busted");
} else if (card == 21) {
printf("won");
} else {
printf("continue");
}
|
C#
if (card > 21) {
Console.WriteLine("busted");
else if (card == 21) {
Concole.WriteLine("won");
} else {
Console.WriteLine("continue");
}
|
Bashif test "$card" -gt "21"; then echo "busted" elif test "$card" -eq "21"; then echo "won" else echo "continue" fi |
Pascal
if card > 21 then
writeln("busted");
else if card = 21 then
writeln("won");
else
writeln("continue");
|
JavaScript
if (card > 21) {
document.write("busted");
} else if (card == 21) {
document.write("won");
} else {
document.write("continue");
}
|
Excel=IF(A1>21;"busted";IF(A1=21;"won";"continue")) |
Rubyif card > 21 print "busted" elseif card == 21 print "won" else print "continue" end |
Fortranif (card > 21) then print*, "busted" else if (card == 21) then print *, "won" else print *, "continue" end if |
Velocity#if( $card > 21 ) busted #elseif( $card == 21 ) won #else continue #end |
ASMcmp dword [card], 21 je @f jl @continue ;; busted jmp @out @@: ;; won jmp @out @continue: ;; continue @out: |
BasicIf Card > 21 Then Print "busted" Else If Card = 21 Then Print "won" Else Print "continue" End If |
Tcl
if {$card > 21} {
puts stdout "busted"
} elseif {$card == 21} {
puts stdout "won"
} else {
puts stdout "continue"
}
|
|