Choice System Cross Reference
This table refers to the most recent language specification of each language. For languages that do not have a specification, the latest officially released implementation is referred to.
Programming language | Structured if | switch/select/case | Arithmetic if | Pattern matching | ||
---|---|---|---|---|---|---|
then | else | else-if | ||||
Ada | Yes | Yes | Yes | Yes | No | No |
C/C++ | Yes | Yes | unneeded | fall-through | No | No |
C# | Yes | Yes | unneeded | Yes | No | No |
Eiffel | Yes | Yes | Yes | Yes | No | No |
F# | Yes | Yes | Yes | unneeded | No | Yes |
Fortran | Yes | Yes | Yes | Yes | Yes | No |
Haskell | Yes | needed | unneeded | unneeded | No | Yes |
Java | Yes | Yes | unneeded | fall-through | No | No |
ECMAScript (JavaScript) | Yes | Yes | unneeded | fall-through | No | No |
Oberon | Yes | Yes | Yes | Yes | No | No |
Perl | Yes | Yes | Yes | Yes | No | No |
PHP | Yes | Yes | Yes | fall-through | No | No |
Pascal, Delphi | Yes | Yes | unneeded | Yes | No | No |
Python | Yes | Yes | Yes | No | No | No |
QuickBASIC | Yes | Yes | Yes | Yes | Yes | No |
Ruby | Yes | Yes | Yes | Yes | No | No |
SQL | Yes | Yes | Yes | Yes | No | No |
Visual Basic, classic | Yes | Yes | Yes | Yes | No | No |
Visual Basic .NET | Yes | Yes | Yes | Yes | No | No |
Windows PowerShell | Yes | Yes | Yes | fall-through | No | No |
- ^ This refers to pattern matching as a distinct conditional construct in the programming language – as opposed to mere string pattern matching support, such as regular expression support.
- 1 2 3 4 5 The often-encountered
else if
in the C family of languages, and in Haskell, is not a language feature but a set of nested and independent if then else statements combined with a particular source code layout. However, this also means that a distinct else-if construct is not really needed in these languages. - 1 2 In Haskell and F#, a separate constant choice construct is unneeded, because the same task can be done with pattern matching.
- 1 2 SQL has two similar constructs that fulfill both roles, both introduced in SQL-92. A "searched CASE" expression CASE WHEN cond1 THEN expr1 WHEN cond2 THEN expr2 ELSE exprDflt END works like if ... else if ... else, whereas a "simple CASE" expression: CASE expr WHEN val1 THEN expr1 ELSE exprDflt END works like a switch statement. For details and examples see Case (SQL).
Read more about this topic: Conditional (computer Programming)
Famous quotes containing the words choice, system, cross and/or reference:
“The majority of persons choose their wives with as little prudence as they eat. They see a trull with nothing else to recommend her but a pair of thighs and choice hunkers, and so smart to void their seed that they marry her at once. They imagine they can live in marvelous contentment with handsome feet and ambrosial buttocks. Most men are accredited fools shortly after they leave the womb.”
—Edward Dahlberg (19001977)
“To care for the quarrels of the past, to identify oneself passionately with a cause that became, politically speaking, a losing cause with the birth of the modern world, is to experience a kind of straining against reality, a rebellious nonconformity that, again, is rare in America, where children are instructed in the virtues of the system they live under, as though history had achieved a happy ending in American civics.”
—Mary McCarthy (19121989)
“If any want to become my followers, let them deny themselves and take up their cross and follow me.”
—Bible: New Testament, Mark 8:34,5.
Jesus.
“I think, for the rest of my life, I shall refrain from looking up things. It is the most ravenous time-snatcher I know. You pull one book from the shelf, which carries a hint or a reference that sends you posthaste to another book, and that to successive others. It is incredible, the number of books you hopefully open and disappointedly close, only to take down another with the same result.”
—Carolyn Wells (18621942)