Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Conditional (computer programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== 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. {| class="wikitable" |- ! rowspan=2 | [[Programming language]] ! colspan=3 | Structured if ! rowspan=2 | [[switch statement|switch]]–select–case ! rowspan=2 | Conditional expressions ! rowspan=2 | [[Arithmetic IF|Arithmetic if]] ! rowspan=2 | [[Pattern matching]]{{ref label|pattern matching|A|none}} |- ! then ! else ! else–if |- |{{rh}}| [[Ada (programming language)|Ada]] | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[ALGOL-60]] | {{yes}} | {{yes}} | {{no2|Unneeded}}{{ref label|choice else if|C|2}} | {{no}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[APL (programming language)|APL]] | {{no}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[Bash (Unix shell)|Bash shell]] | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[C (programming language)|C]], [[C++]] | {{no}} | {{yes}} | {{no2|Unneeded}}{{ref label|preprocessor elif|B|1}}{{ref label|choice else if|C|6}} | {{yes2|Fall-through}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[C Sharp (programming language)|C#]] | {{no}} | {{yes}} | {{no2|Unneeded}}{{ref label|preprocessor elif|B|2}}{{ref label|choice else if|C|2}} | {{yes}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[COBOL]] | {{no2|Unneeded}} | {{yes}} | {{no2|Unneeded}}{{ref label|choice else if|C|2}} | {{yes}} | {{no}} | {{no}} | {{no}} |- |{{rh}}| [[Eiffel (programming language)|Eiffel]] | {{yes}} | {{yes}} | {{yes}} | {{yes|[[switch statement#Eiffel|Yes]]}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[F Sharp (programming language)|F#]] | {{yes}} | {{yes}} | {{yes}} | {{yes}}{{ref label|choice const|D|1}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[Fortran]] | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{yes}}{{ref label|fortran|G|none}} | {{yes}}{{ref label|fortran|I|none}} | {{no}} |- |{{rh}}| [[Go (programming language)|Go]] | {{no}} | {{yes}} | {{no2|Unneeded}}{{ref label|choice else if|C|1}} | {{yes}} | {{no}} | {{no}} | {{no}} |- |{{rh}}| [[Haskell (programming language)|Haskell]] | {{yes}} | {{yes2|Needed}} | {{no2|Unneeded}}{{ref label|choice else if|C|3}} | {{yes}}{{ref label|choice const|D|2}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[Java (programming language)|Java]] | {{no}} | {{yes}} | {{no2|Unneeded}}{{ref label|choice else if|C|4}} | {{yes2|Fall-through}}<ref name="JLS">[http://java.sun.com/docs/books/jls/download/langspec-3.0.pdf Java.sun.com], Java Language Specification, 3rd Edition.</ref> | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[ECMAScript]] ([[JavaScript]]) | {{no}} | {{yes}} | {{no2|Unneeded}}{{ref label|choice else if|C|5}} | {{yes2|Fall-through}}<ref name="ECMA-262">[http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf Ecma-international.org] {{Webarchive|url=https://web.archive.org/web/20150412040502/http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf |date=2015-04-12 }} ECMAScript Language Specification, 5th Edition.</ref> | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[Mathematica]] | {{no}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[Oberon (programming language)|Oberon]] | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{no}} | {{no}} |- |{{rh}}| [[Perl]] | {{no}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[PHP]] | {{no}} | {{yes}} | {{yes}} | {{yes2|Fall-through}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[Pascal (programming language)|Pascal]], [[Object Pascal]] ([[Delphi (programming language)|Delphi]]) | {{yes}} | {{yes}} | {{no2|Unneeded}} | {{yes}} | {{no}} | {{no}} | {{no}} |- |{{rh}}| [[Python (programming language)|Python]] | {{no}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[QuickBASIC]] | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{no}} | {{no}} |- |{{rh}}| [[Ruby (programming language)|Ruby]] | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{yes}}{{ref label|ruby|H|none}} |- |{{rh}}| [[Rust (programming language)|Rust]] | {{no}} | {{yes}} | {{yes}} | {{yes}}{{ref label|choice const|D|3}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[Scala (programming language)|Scala]] | {{no}} | {{yes}} | {{no2|Unneeded}}{{ref label|choice else if|C|4}} | {{yes2|Fall-through}}{{Citation needed|date=November 2015}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[SQL]] | {{yes}}{{ref label|SQL|F|1}} | {{yes}} | {{yes}} | {{yes}}{{ref label|SQL|F|2}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[Swift (programming language)|Swift]] | {{no}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[Tcl]] | {{no}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{yes}} |- |{{rh}}| [[Visual Basic]], classic | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[Visual Basic .NET]] | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{yes}} | {{no}} | {{no}} |- |{{rh}}| [[Windows PowerShell]] | {{no}} | {{yes}} | {{yes}} | {{yes2|Fall-through}} | {{yes}} | {{no}} | {{no}} |} {{ordered list|type=upper-alpha |{{note label|pattern matching|A|none}} 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. |{{note label|preprocessor elif|B|1}}{{note label|preprocessor elif|B|2}} An #ELIF directive is used in the [[preprocessor]] sub-language that is used to modify the code before compilation; and to [[Include directive|include]] other files. |{{note label|choice else if|C|1}} {{note label|choice else if|C|2}} {{note label|choice else if|C|3}} {{note label|choice else if|C|4}} {{note label|choice else if|C|5}} {{note label|choice else if|C|6}}The often-encountered <code>else if</code> in the C family of languages, and in COBOL and 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. |{{note label|choice const|D|1}} {{note label|choice const|D|2}} {{note label|choice const|D|3}} Case-expressions in Haskell and match-expressions in F# and Haskell allow both switch-case and pattern matching usage. |{{note label|case regexp|E|none}} In a Ruby <code>case</code> construct, [[regular expression]] matching is among the conditional flow-control alternatives available. For an example, see [https://stackoverflow.com/q/6803647 this] Stack Overflow question. |{{note label|SQL|F|1}}{{note label|SQL|F|2}} SQL has two similar constructs that fulfill both roles, both introduced in [[SQL-92]]. A "searched <code>CASE</code>" expression {{code|2=sql|CASE WHEN cond1 THEN expr1 WHEN cond2 THEN expr2 [...] ELSE exprDflt END}} works like <code>if ... else if ... else</code>, whereas a "simple <code>CASE</code>" expression: {{code|2=sql|CASE expr WHEN val1 THEN expr1 [...] ELSE exprDflt END}} works like a switch statement. For details and examples see [[Case (SQL)]]. |{{note label|fortran|G|none}} Fortran 90 added the <code>MERGE</code> intrinsic. Fortran 2023 added the C-like ternary operator. |{{note label|ruby|H|none}} Pattern matching was added in Ruby 3.0.<ref>{{cite web |title=Pattern Matching |url=https://docs.ruby-lang.org/en/3.0.0/doc/syntax/pattern_matching_rdoc.html |website=Documentation for Ruby 3.0}}</ref> Some pattern matching constructs are still experimental. |{{note label|fortran|I|none}} Arithmetic <code>if</code> was marked as obsolescent in Fortran 90. It was deleted as of the Fortran 2018 Standard. }}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)