Content deleted Content added
Reorganizing more apostrophes (only the last three subsections of the "control flow" section remain to be reviewed) |
m →Functions: {{codett}} |
||
(48 intermediate revisions by 12 users not shown) | |||
Line 1:
{{Short description|None}}
{{Refimprove|date=February 2009}}
{{ProgLangCompare}}
Line 7 ⟶ 8:
Generally, ''var'', {{var|var}}, or {{var serif|var}} is how variable names or other non-literal values to be interpreted by the reader are represented. The rest is literal code. [[Guillemet]]s ({{code|«}} and {{code|»}}) enclose optional sections. {{keypress|Tab}} indicates a necessary (whitespace) indentation.
{{Clear}}
== Type identifiers ==
=== [[Integer (computer science)|Integer]]s ===
{| class="wikitable sortable"
! rowspan=2|
Line 35 ⟶ 34:
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012">Ada Reference Manual – Language and Standard Libraries; ISO/IEC 8652:201x (E), {{cite web |url=http://www.ada-auth.org/standards/12rm/RM-Final.pdf |title=Reference Manual |access-date=2013-07-19 |url-status=dead |archive-url=https://web.archive.org/web/20110427190723/http://www.ada-auth.org/standards/12rm/RM-Final.pdf |archive-date=2011-04-27 }}</ref>
| {{code|range -2**7 .. 2**7 - 1|ada}}{{ref|Ada_range|[j]}}
| {{code|range 0 .. 2**8 - 1|ada}}{{ref|Ada_range|[j]}} or {{code|mod 2**8|ada}}{{ref|Ada_mod|[k]}}
| {{code|range -2**15 .. 2**15 - 1|ada}}{{ref|Ada_range|[j]}}
| {{code|range 0 .. 2**16 - 1|ada}}{{ref|Ada_range|[j]}} or {{code|mod 2**16|ada}}{{ref|Ada_mod|[k]}}
| {{code|range -2**31 .. 2**31 - 1|ada}}{{ref|Ada_range|[j]}}
| {{code|range 0 .. 2**32 - 1|ada}}{{ref|Ada_range|[j]}} or {{code|mod 2**32|ada}}{{ref|Ada_mod|[k]}}
| {{code|range -2**63 .. 2**63 - 1|ada}}{{ref|Ada_range|[j]}}
| {{code|mod 2**64|ada}}{{ref|Ada_mod|[k]}}
|
|
| {{n/a}}
|-
| rowspan=2| [[ALGOL 68]] (variable-width)
| rowspan=2|
| rowspan=2 {{n/a}}
| rowspan=2|
| rowspan=2 {{n/a}}
| rowspan=2|
| rowspan=2 {{n/a}}
| rowspan=2|
| rowspan=2 {{n/a}}
|
| {{n/a}}
| rowspan=2|
|-
| colspan=2 align=center|
|-
| [[C (programming language)|C]] ([[C99]] fixed-width)
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=5 {{n/a}}
|-
Line 78 ⟶ 77:
|-
| [[C (programming language)|C]] ([[C99]] variable-width)
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
| rowspan=2|
|-
| [[C++]] ([[C++11]] variable-width)
|-
| [[Objective-C]] ([[Cocoa (API)|Cocoa]])
|
|
|
|
|
|
|
|
|
|
|-
| [[C Sharp (programming language)|C#]]
|
|
| rowspan=2|
|
| rowspan=2|
|
| rowspan=2|
|
|
|
| <code>System.Numerics.<wbr/>BigInteger</code><br
|-
| [[Java (programming language)|Java]]
|
| {{n/a}}
|
| {{n/a}}
| {{n/a}}
Line 127 ⟶ 126:
|-
| [[Go (programming language)|Go]]
|
|
|
|
|
|
|
|
|
|
|
|-
| [[Rust (programming language)|Rust]]
|
|
|
|
|
|
|
|
|
|
| {{n/a}}
|-
| [[Swift (programming language)|Swift]]
|
|
|
|
|
|
|
|
|
|
|-
| [[D (programming language)|D]]
|
|
|
|
|
|
|
|
| {{n/a}}
| {{n/a}}
|
|-
| [[Common Lisp]]<ref name="HyperSpec">{{cite web|url=http://www.lispworks.com/documentation/HyperSpec/Front/index.htm|title=Common Lisp HyperSpec (TM)|work=lispworks.com|access-date=30 January 2017}}</ref>
|
|
|
|
|
|
|
|
|
|
|
|-
| [[Scheme (programming language)|Scheme]]
Line 214 ⟶ 213:
|
|
|
|-
| [[Pascal (programming language)|Pascal]] ([[Free Pascal|FPC]])
|
|
|
|
|
|
|
|
|
|
| {{n/a}}
|-
| [[Visual Basic (classic)|Visual Basic]]
| {{n/a}}
| rowspan=2|
|
| {{n/a}}
|
| {{n/a}}
| colspan=2 {{n/a}}
Line 241 ⟶ 240:
|-
| [[Visual Basic .NET]]
|
|
|
|
|
|
|
| <code>System.Numerics<wbr/>.BigInteger</code><br
|-
| [[FreeBasic]]
|
|
|
|
|
|
|
|
|
|
| {{n/a}}
|-
Line 268 ⟶ 267:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
| {{n/a}}
|
|-
| [[Python (programming language)|Python]] 3.x
Line 278 ⟶ 277:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
|-
| [[
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
Line 289 ⟶ 288:
|-
| [[Fortran]]
|
| {{n/a}}
|
| {{n/a}}
|
| {{n/a}}
|
| {{n/a}}
|
Line 304 ⟶ 303:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
| {{n/a}}
|
| {{n/a}}
| colspan=2 {{n/a}}
Line 317 ⟶ 316:
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
|
|-
| [[Raku (programming language)|Raku]]
|
|
|
|
|
|
|
|
|
| colspan=2 {{n/a}}
|-
Line 336 ⟶ 335:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
| {{n/a}}
|
|-
| [[Erlang (programming language)|Erlang]]{{ref|Erlang_int|[n]}}
Line 345 ⟶ 344:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
| {{n/a}}
|
|-
| [[Scala (programming language)|Scala]]
|
| {{n/a}}
|
|
|
| {{n/a}}
|
| {{n/a}}
| {{n/a}}
| {{n/a}}
|
|-
| [[Seed7]]
Line 369 ⟶ 368:
| {{n/a}}
| {{n/a}}
|
| {{n/a}}
| {{n/a}}
| {{n/a}}
|
|-
| [[Smalltalk]]
Line 380 ⟶ 379:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
| {{n/a}}
|
|-
| [[Windows PowerShell]]
Line 395 ⟶ 394:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
| {{n/a}}
| rowspan=2|
| {{n/a}}
|
|
|
|-
| [[F Sharp (programming language)|F#]]
|
|
|
|
|
|
|
|
|
|
|-
| [[Standard ML]]
| {{n/a}}
|
| colspan=2 {{n/a}}
|
|
|
|
|
|
|
|-
| [[
|
|
|
|
|
|
|
|
|
|
|
|-
| [[Eiffel (programming language)|Eiffel]]
|
|
|
|
|
|
|
|
|
|
| {{n/a}}
|-
| [[COBOL]]{{ref|Cobol|[h]}}
|
|
|
|
|
|
|
|
| {{n/a}}
| {{n/a}}
Line 472 ⟶ 471:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
|-
| [[Wolfram Language]]
Line 480 ⟶ 479:
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
|
|}
* {{note|a68|a}} The ''standard'' constants
* {{note|Java char|b}} Commonly used for characters.
* {{note|CInt|c}} The ALGOL 68, C and C++ languages do not specify the exact width of the integer types
* {{note|scalars|d}} Perl 5 does not have distinct types. Integers, floating point numbers, strings, etc. are all considered "scalars".
* {{note|PHP bignum|e}} PHP has two arbitrary-precision libraries. The BCMath library just uses strings as datatype. The GMP library uses an internal "resource" type.
* {{note|Kinds|f}} The value of
* {{note|a68g|g}} [[ALGOL 68]]G's runtime option
* {{note|Cobol|h}} [[COBOL]] allows the specification of a required precision and will automatically select an available type capable of representing the specified precision. "
* {{note|Smalltalk|i}} [[Smalltalk]] automatically chooses an appropriate representation for integral numbers. Typically, two representations are present, one for integers fitting the native word size minus any tag bit ({{mono|SmallInteger}}) and one supporting arbitrary sized integers ({{mono|LargeInteger}}). Arithmetic operations support polymorphic arguments and return the result in the most appropriate compact representation.
* {{note|Ada_range|j}} [[Ada (programming language)|Ada]] range types are checked for boundary violations at run-time (as well as at compile-time for static expressions). Run-time boundary violations raise a "constraint error" exception. Ranges are not restricted to powers of two. Commonly predefined Integer subtypes are: Positive (
* {{note|
* {{note|Scala char|l}} Commonly used for characters like Java's char.
* {{note|PHP 32/64 bit long|m}}
* {{note|
* {{note|
=== [[Floating point]] ===
{| class="wikitable sortable"
!
Line 509 ⟶ 507:
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
|
|
| {{n/a}}
|-
| [[ALGOL 68]]
|
|
|
|-
| [[C (programming language)|C]]
| rowspan=3|
| rowspan=5|
| rowspan=3|
|-
| [[C++]] (STL)
|-
| [[Objective-C]] ([[Cocoa (API)|Cocoa]])
|
|-
| [[C Sharp (programming language)|C#]]
| rowspan=2|
| rowspan=
|-
| [[Java (programming language)|Java]]
|-
| [[Go (programming language)|Go]]
|
|
|-
| [[Rust (programming language)|Rust]]
|
|
| <code>f16, f128</code>
|-
| [[Swift (programming language)|Swift]]
|
|
|
|
|-
| [[D (programming language)|D]]
|
|
|
|
|-
| [[Common Lisp]]
|
|
|
|-
| [[Scheme (programming language)|Scheme]]
Line 570 ⟶ 569:
|-
| [[Pascal (programming language)|Pascal]] ([[Free Pascal|FPC]])
|
|
|
|
|-
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=3|
| rowspan=3|
| rowspan=3 {{n/a}}
|-
Line 586 ⟶ 585:
| [[Python (programming language)|Python]]
| rowspan=2 {{n/a}}
|
|
|-
| [[JavaScript]]
|
| {{n/a}}
|-
| [[
| <!-- ''x'' = ''value f''; -->
| <!-- ''x'' = ''value''; -->
Line 604 ⟶ 603:
| [[PHP]]
|
|
|
|-
Line 613 ⟶ 612:
|-
| [[Raku (programming language)|Raku]]
|
|
|
|
|-
| [[Ruby (programming language)|Ruby]]
| {{n/a}}
|
| rowspan=4 {{n/a}}
|-
| [[Scala (programming language)|Scala]]
|
|
|-
| [[Seed7]]
| {{n/a}}
|
|-
| [[Smalltalk]]
|
|
|-
| [[Windows PowerShell]]
Line 642 ⟶ 641:
| [[OCaml]]
| {{n/a}}
| rowspan=2|
| rowspan=3 {{n/a}}
|-
| [[F Sharp (programming language)|F#]]
|
|-
| [[Standard ML]]
| {{n/a}}
|
|
|-
| [[
|
|
|
|-
| [[Eiffel (programming language)|Eiffel]]
|
|
|
|-
| [[COBOL]]
|
|
|
|-
| [[Mathematica]]
Line 672 ⟶ 671:
| {{n/a}}
|
|
|}
* {{note|a68_real|a}} The ''standard'' constants
* {{note|lax floats|b}} declarations of single precision often are not honored
* {{note|real kinds|c}} The value of
* {{note|a68g-real|d}} [[ALGOL 68]]G's runtime option
* {{note|Cobol-ieee|e}} These [[IEEE]] floating-point types will be introduced in the next COBOL standard.
* {{note|C-long-double|f}} Same size as
* {{note|Swift-long-double|g}} Swift supports 80-bit [[Extended precision#Language support|extended precision]] floating point type, equivalent to
=== [[Complex number]]s ===
{| class="wikitable sortable"
!
Line 694 ⟶ 692:
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| {{n/a}}
|
|
|
|-
| [[ALGOL 68]]
| {{n/a}}
|
|
|
|-
| [[C (programming language)|C]] ([[C99]])<ref>{{cite web|url=https://www.gnu.org/software/libc/manual/html_node/Complex-Numbers.html#Complex-Numbers|title=The GNU C Library: Complex Numbers|work=gnu.org|access-date=30 January 2017}}</ref>
| {{n/a}}
|
|
| rowspan=7 {{n/a}}
|-
| [[C++]] (STL)
| {{n/a}}<!-- No std::complex<int>. See C++ standard section 26.2 paragraph 2 -->
|
|
|-
| [[C Sharp (programming language)|C#]]
| {{n/a}}
| {{n/a}}
|
|-
| [[Java (programming language)|Java]]
Line 727 ⟶ 725:
| [[Go (programming language)|Go]]
| {{n/a}}
|
|
|-
| [[D (programming language)|D]]
| {{n/a}}
|
|
|-
| [[Objective-C]]
Line 765 ⟶ 763:
| {{n/a}}
| {{n/a}}
|
|-
| [[Perl]]
|
|
|
|
|-
| [[Raku (programming language)|Raku]]
|
|
|
|
|-
| [[Python (programming language)|Python]]
|
|
|
| rowspan=15 {{n/a}}
|-
| [[
| {{n/a}}
| {{n/a}}
|
|-
| [[
| {{n/a}}
| {{n/a}}
Line 800 ⟶ 798:
|-
| [[Ruby (programming language)|Ruby]]
|
| {{n/a}}
|
|-
| [[Scala (programming language)|Scala]]
Line 812 ⟶ 810:
| {{n/a}}
| {{n/a}}
|
|-
| [[Smalltalk]]
|
|
|
|-
| [[Windows PowerShell]]
Line 827 ⟶ 825:
| {{n/a}}
| {{n/a}}
|
|-
| [[F Sharp (programming language)|F#]]
|
|
|
|-
| [[Standard ML]]
Line 839 ⟶ 837:
| {{n/a}}
|-
| [[
| {{n/a}}
|
|
|-
| [[Eiffel (programming language)|Eiffel]]
Line 855 ⟶ 853:
|-
| [[Mathematica]]
|
| {{n/a}}
| {{n/a}}
|
|}
* {{note|complex kinds|a}} The value of
* {{note|generic type|b}} Generic type which can be instantiated with any base floating point type.
=== Other variable types ===
{| class="wikitable sortable"
! rowspan=2|
! colspan=2| Text
! rowspan=2| [[Boolean
! rowspan=2| [[Enumerated type|Enumeration]]
! rowspan=2| [[Object (computer science)|Object]]/[[Top type|Universal]]
Line 877 ⟶ 874:
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
|
|
|
| <code>(''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'')</code>
|
|-
| [[ALGOL 68]]
|
|
|
| {{
| {{
|-
| [[C (programming language)|C]] ([[C99]])
| rowspan=2|
| {{
| rowspan=2|
| rowspan=3| <code>enum ''«name»'' { ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' };</code>
| rowspan=2| <code>[[void type|void]] [[pointer (computer programming)|*]]</code>
|-
| [[C++]] (STL)
| [[C++ string handling|
|-
| [[Objective-C]]
|
|
|
|
|-
| [[C Sharp (programming language)|C#]]
| rowspan=2|
|
|
| <code>enum ''name'' { ''item<sub>1</sub>''« = ''value''», ''item<sub>2</sub>''« = ''value''», ''...'' }</code>
| object
|-
| [[Java (programming language)|Java]]
|
|
| <code>enum ''name'' { ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }</code>
|
|-
| [[Go (programming language)|Go]]
|
|
|
| <code>const (<br
| <code>interface{}</code>
|-
| [[Rust (programming language)|Rust]]
|
|
|
| <code>enum ''name'' { ''item{{sub|1}}''« = ''value''», ''item{{sub|2}}''« = ''value''», ''...'' }</code>
|
|-
| [[Swift (programming language)|Swift]]
|
|
|
| <code>enum ''name'' { case ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }</code>
|
|-
| [[D (programming language)|D]]
|
|
|
| <code>enum ''name'' { ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }</code>
|
|-
| [[Common Lisp]]
|
|
|
| <code>(member ''item<sub>1</sub>'' ''item<sub>2</sub>'' ''...'')</code>
|
|-
| [[Scheme (programming language)|Scheme]]
Line 969 ⟶ 966:
|-
| Pascal (ISO)
| rowspan=2|
| {{
| rowspan=2|
| rowspan=2| <code>( ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' )</code>
| {{
|-
| [[Object Pascal]] ([[Delphi (software)|Delphi]])
|
|
|-
| [[Visual Basic (classic)|Visual Basic]]
| {{
| rowspan=3|
| rowspan=3|
| rowspan=3| <code>Enum ''name''<br
|
|-
| [[Visual Basic .NET]]
|
|
|-
| [[Xojo]]
| {{
|
|-
| [[Python (programming language)|Python]]
| {{
|
|
| {{pre|1=
{{codett|2=python|import enum}}
| {{code|object}}▼
{{codett|2=python|class Name(enum.Enum):}}
''item{{sub|1}}'' = ''value''
''item{{sub|2}}'' = ''value''
''...''
}}
|-
| [[
| {{
|
|
|
|
|-
| [[
|
|
Line 1,016 ⟶ 1,020:
|-
| [[Fortran]]
|
|
|
|
|
|-
| [[PHP]]
| {{
|
|
|
| (type declaration omitted)
|-
| [[Perl]]
| {{
|
|
|
|
|-
| [[Raku (programming language)|Raku]]
|
|
|
| <code>enum ''name<item<sub>1</sub> item<sub>2</sub> ...>''</code><br
|
|-
| [[Ruby (programming language)|Ruby]]
| {{
|
|
|
|
|-
| [[Scala (programming language)|Scala]]
|
|
|
| <code>object ''name'' extends Enumeration {<br
|
|-
| [[Seed7]]
|
|
|
| <code>const type'': name'' is new enum<br
|
|-
Line 1,072 ⟶ 1,076:
|-
| [[OCaml]]
| rowspan=3|
| rowspan=3|
| rowspan=3|
| {{
| {{
|-
| [[F Sharp (programming language)|F#]]
| <code>type ''name'' = ''item<sub>1</sub>'' = ''value'' {{pipe}}''item<sub>2</sub>'' = ''value'' {{pipe}} ''...''</code>
|
|-
| [[Standard ML]]
| {{
| {{
|-
| [[
|
|
|
| {{
| {{
|-
| [[Eiffel (programming language)|Eiffel]]
|
|
|
| {{
|
|-
| [[COBOL]]
|
| <code>''PIC X(''string length'')''</code> or <code>PIC X«X...»</code>
| <code>''PIC 1«(''number of digits'')»''</code> or <code>PIC 1«1...»</code>
| {{
|
|-
| [[Mathematica]]
| {{
|
|
|
| {{
|}
* {{note|string|a}} specifically, strings of arbitrary length and automatically managed.
* {{note|int bool|b}} This language represents a boolean as an integer where false is represented as a value of zero and true by a non-zero value.
* {{note|Ruby's bool|c}} All values evaluate to either true or false. Everything in ''
* {{note|string as char|d}}This language does not have a separate character type. Characters are represented as strings of length 1.
* {{note|enum|e}} Enumerations in this language are algebraic types with only nullary constructors
* {{note|logical kinds|f}} The value of ''
== Derived types ==
=== [[Array data type|Array]] ===
▲{{further|Comparison of programming languages (array)}}
{| class="wikitable sortable"
|- valign="top"
Line 1,140 ⟶ 1,141:
|- valign="top"
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>array (''
| <code>array (''
| <code>array (''
| <code>array (''
|- valign="top"
| [[ALGOL 68]]
| <code>
| <code>
| <code>flex
| <code>flex
|- valign="top"
| [[C (programming language)|C]] ([[C99]])
| <code>''type name''[''size'']</code>{{ref|C's array|[a]}}
| <code>''type name''[''size<sub>1</sub>''][''size<sub>2</sub>'']</code>{{ref|C's array|[a]}}
| <code>''type'' *''name''</code><br
|
|- valign="top"
Line 1,165 ⟶ 1,166:
| <code>''type''[]</code>
| <code>''type''[{{Not a typo|,,}}''...'']</code>
| <code>System<wbr/>.Collections<wbr/>.ArrayList</code><br
|
|- valign="top"
Line 1,188 ⟶ 1,189:
| [[Rust (programming language)|Rust]]
| <code>[''type; size'']</code>
| <code><nowiki>[[</nowiki>''type; size<sub>1</sub>'']''; size<sub>2</sub>'']</code>
| <code>Vec<''type''></code>
| <code>Vec<Vec<''type''>></code>
Line 1,204 ⟶ 1,205:
|
|- valign="top"
| [[
| {{n/a}}
| {{n/a}}
Line 1,210 ⟶ 1,211:
|- valign="top"
| [[Common Lisp]]
| {{code|2=lisp|(simple-array type (dimension))}}
|
| {{code|2=lisp|(array type (dimension))}}
|
|- valign="top"
| [[Scheme (programming language)|Scheme]]
Line 1,229 ⟶ 1,230:
| [[Pascal (programming language)|Pascal]]
| rowspan=2|<code>array[''first''..''last''] of ''type''</code>{{ref|subrange|[c]}}
| rowspan=2|<code>array[''first<sub>1</sub>''..''last<sub>1</sub>''] of array[''first<sub>2</sub>''..''last<sub>2</sub>'']'' ...'' of ''type''</code>{{ref|subrange|[c]}}<br
| {{n/a}}
| {{n/a}}
|- valign="top"
| [[Object Pascal]] ([[Delphi (software)|Delphi]])
| <code>array of'' type''</code>
| <code>array of array ''...'' of ''type''</code>
Line 1,246 ⟶ 1,247:
| <code>''type''()</code>
| <code>''type''({{Not a typo|,,}}''...'')</code>
| <code>System<wbr/>.Collections<wbr/>.ArrayList</code><br
|
|- valign="top"
Line 1,255 ⟶ 1,256:
|
|- valign="top"
| [[
| <code>x = ''type''[''size''];</code>
| <code>x = ''type''[''size<sub>1</sub>'','' size<sub>2</sub>'', ''...''];</code>
Line 1,298 ⟶ 1,299:
|- valign="top"
| [[Seed7]]
| <code>array ''type''</code><br
| <code>array array ''type''</code><br
| <code>array ''type''</code><br
| <code>array array ''type''</code><br
|- valign="top"
| [[Smalltalk]]
Line 1,322 ⟶ 1,323:
|- valign="top"
| [[F Sharp (programming language)|F#]]
| <code>''type'' []</code><br
| <code>''type'' [{{Not a typo|,,}}''...'']</code>
| <code>System<wbr/>.Collections<wbr/>.ArrayList</code><br
|
|- valign="top"
Line 1,333 ⟶ 1,334:
|
|- valign="top"
| [[
| <code>{{codett|2=haskell|1=x = Array.array (0,}} ''size''-1) ''list_of_association_pairs''</code>
| <code>{{codett|2=haskell|1=x = Array.array ((0, 0,}}''...''), (''size<sub>1</sub>''-1, ''size<sub>2</sub>''-1,''...'')) ''list_of_association_pairs''</code>
|
|
Line 1,341 ⟶ 1,342:
| [[COBOL]]
| <code>''level-number type'' OCCURS ''size'' «TIMES».</code>
| {{
| <code>''level-number type'' OCCURS ''min-size'' TO ''max-size'' {{codett|2=cobolfree|1=«TIMES» DEPENDING «ON»}} ''size''.</code>{{ref|COBOL DEPENDING ON clause|[e]}}
| {{n/a}}
|}
* {{note|C's array|a}}In most expressions (except the <code>[[sizeof]]</code> and
* {{note|Java's array|b}} The C-like <code>''type'' x[]</code> works in Java, however <code>''type''[] x</code> is the preferred form of array declaration.
* {{note|subrange|c}} Subranges are used to define the bounds of the array.
* {{note|JavaScript's array|d}} JavaScript's array are a special kind of object. <!-- explain array(size) thing -->
* {{note|COBOL DEPENDING ON clause|e}} The
=== Other types ===
{| class="wikitable sortable"
! rowspan=2|
Line 1,364:
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>type ''name'' is «abstract» «tagged» «limited» ''[''record{{indent|2}}''field{{sub|1}}'' : ''type'';{{indent|2}}''field{{sub|2}}'' : ''type'';{{indent|2}}''...''<br
| {{
| {{Any}} combination of records, unions, and enumerations (as well as references to those, enabling recursive types).
| <code>type ''name'' (''variation'' : ''discrete_type'') is record{{indent|2}}case ''variation'' is{{indent|4}}when ''choice_list{{sub|1}}'' =>{{indent|6}}''fieldname{{sub|1}}'' : ''type'';{{indent|6}}''...''{{indent|4}}when ''choice_list{{sub|2}}'' =>{{indent|6}}''fieldname{{sub|2}}'' : ''type'';{{indent|6}}''...''{{indent|4}}''...''{{indent|2}}end case;<br
|-
| [[ALGOL 68]]
Line 1,376:
| [[C (programming language)|C]] ([[C99]])
| rowspan=2| <code>struct ''«name»'' {''type name'';''...''};</code>
| rowspan=2 {{
| rowspan=3 {{
| rowspan=3| <code>union {''type name'';''...''};</code>
|-
Line 1,390:
| <code>(''val{{sub|1}}'', ''val{{sub|2}}'', ''...'' )</code>
|
| rowspan=3 {{
|-
| [[Java (programming language)|Java]]
| {{
|
|
|-
| [[
|
| {{
|
|-
Line 1,409:
|-
| [[Go (programming language)|Go]]
| <code>struct { {{indent|2}}''«name» type''{{indent|2}}''...''<br
|
|
Line 1,421:
|-
| [[Swift (programming language)|Swift]]
| <code>struct ''name'' {''{{indent|2}}''var'' name «'':'' type»{{indent|2}}...<br
| <code>(''«name{{sub|1}}'':''» val{{sub|1}}'', ''«name{{sub|2}}'':''» val{{sub|2}}'', ''«name{{sub|3}}'':''» val{{sub|3}}'', ''...'' )</code>
| <code>enum ''name'' { case ''Foo«''(''types'')» case ''Bar'' «(''types'')» ''...'' }</code>
Line 1,427:
|-
| [[Common Lisp]]
| {{code|2=lisp|(defstruct name slot-name (slot-name initial-value) (slot-name initial-value :type type) ...)
| rowspan=3| <code>(cons ''val{{sub|1}} val{{sub|2}}'')</code>{{ref|pair only|[c]}}
|
Line 1,433:
|-
| [[Scheme (programming language)|Scheme]]
| {{
|
|
Line 1,443:
|-
| [[Pascal (programming language)|Pascal]]
| <code>record{{indent|2}}''name'': ''type'';{{indent|2}}''...<br
| {{
| {{
| <code>record{{indent|2}}case ''type'' of{{indent|2}}''value'': (''types'');{{indent|2}}''...''<br
|-
| [[Visual Basic (classic)|Visual Basic]]
Line 1,455:
|-
| [[Visual Basic .NET]]
| <code>Structure ''name''{{indent|2}}Dim ''name'' As ''type''{{indent|2}}''...''<br
| <code>(''val{{sub|1}}'', ''val{{sub|2}}'', ''...'' )</code>
|
Line 1,461:
|-
| [[Python (programming language)|Python]]
| {{
| <code>«(''»val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'' «)»</code>
|
| {{
|-
| [[
| <code>struct {''name [=value], ...''}</code>
|
Line 1,473:
|-
| [[Fortran]]
| <code>TYPE ''name{{indent|2}}type'' :: ''name{{indent|2}}...<br
|
|
Line 1,479:
|-
| [[PHP]]
| {{
|
|
Line 1,485:
|-
| [[Perl]]
| {{
|
|
| rowspan=3 {{
|-
| [[Raku (programming language)|Raku]]
| {{
|
|
Line 1,503:
| <code>case class ''name''(«''var''» ''name'': ''type'', ''...'')</code>
| <code>(''val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'' )</code>
| <code>abstract class ''name''{{indent|2}}case class ''Foo''(«''parameters''») extends ''name''{{indent|2}}case class ''Bar''(«''parameters''») extends ''name''{{indent|2}}''...''</code><br
|
|-
Line 1,516:
| rowspan=2| <code>«(»''val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'' «)»</code>
| rowspan=2| <code>type ''name'' = ''Foo'' «of ''type''» {{pipe}} ''Bar'' «of ''type''» {{pipe}} ''...''</code>
| rowspan=4 {{
|-
| [[F Sharp (programming language)|F#]]
Line 1,525:
| <code>datatype ''name'' = ''Foo'' «of ''type''» {{pipe}} ''Bar'' «of ''type''» {{pipe}} ''...''</code>
|-
| [[
| <code>data ''Name'' = ''Constr'' {''name'' :: ''type'',''...''}</code>
| <code>data ''Name'' = ''Foo'' «''types''» {{pipe}} ''Bar'' «''types''» {{pipe}} ''...''</code>
|-
| [[COBOL]]
| <code>''{{codett|2=cobolfree|level-number name type clauses}}''.{{indent|2}}''{{codett|2=cobolfree|level-number+n name type clauses}}''.{{indent|2}}''...''</code>
| {{
| {{
| <code>''name'' REDEFINES ''variable type''.</code>
|}
* {{note|just classes|a}} Only classes are supported.
* {{note|C++'s struct|b}}
* {{note|pair only|c}} pair only
* {{note|Perl's records|d}} Although Perl doesn't have records, because Perl's type system allows different data types to be in an array, "hashes" (associative arrays) that don't have a variable index would effectively be the same as records.
Line 1,543:
== Variable and constant declarations ==
{| class="wikitable sortable"
!
Line 1,571 ⟶ 1,570:
|-
| [[C Sharp (programming language)|C#]]
| <code>''type name<sub>1</sub>''« = ''initial_value''», ''name<sub>2</sub>''« = ''initial_value''», ''...'';</code><br
| <code>const ''type name'' = ''value'', ''name'' = ''value'', ''...'';</code><br
| <code>using ''synonym'' = ''type'';</code>
|-
| [[D (programming language)|D]]
| <code>''type name''« = ''initial_value''»;</code><br
| <code>const ''type name'' = ''value'';</code><br
| <code>alias ''type synonym'';</code>
|-
Line 1,585 ⟶ 1,584:
| rowspan=2 {{n/a}}
|-
| [[
| <code>var ''name''« = ''initial_value''»;</code> or<br
| <code>const ''name'' = ''value'';</code> (since [[ECMAScript]] 2015)
|-
| [[Go (programming language)|Go]]
| <code>var ''name type''« = ''initial_value''»</code><br
| <code>const ''name «type»'' = ''value''</code>
| <code>type ''synonym type''</code>
|-
| [[Rust (programming language)|Rust]]{{ref|Rust declaration|[f]}}
| <code>let mut ''name''«: ''type''»« = ''initial_value''»;</code><br
| <code>let ''name''«: ''type''»« = ''initial_value''»;</code><br
| <code>type ''synonym'' = ''typename'';</code>
|-
Line 1,605 ⟶ 1,604:
|-
| [[Common Lisp]]
| <code>(defparameter ''name initial-value'')</code><br
| <code>(defconstant ''name value'')</code>
| <code>(deftype ''synonym'' () <nowiki>'</nowiki>''type'')</code>
Line 1,615 ⟶ 1,614:
|-
| [[ISLISP]]
| <code>(defglobal ''name initial_value'')</code><br
| <code>(defconstant ''name value'')</code>
| {{n/a}}
Line 1,628 ⟶ 1,627:
| rowspan=3| See notes to left.
Constants use the same syntax, and:
* use
* have a restriction to only certain primitive types<br
|
|-
Line 1,635 ⟶ 1,634:
| The variable declaration syntax of VB.NET is unusually difficult to precisely describe.
Given that there exist the identifier suffixes ("modifiers"):
*
*
*
and that
* a
* a
* a
** <code>''identifier'' As ''object_creation_expression''</code>'' (object initializer declarator)'',
** <code>''modified_identifier'' «As ''non_array_type''«''array_rank_specifier''»»« = ''initial_value»''</code> ''(single declarator)'', or
Line 1,647 ⟶ 1,646:
valid declaration statements are of the form
{{In5}}<code>Dim ''declarator_list''</code>,
where, for the purpose of semantic analysis, to convert the
* The
* The <code>As New ''type...''</code> of each ''object initializer declarator'' is replaced with <code>As ''type'' = New ''type...''</code>
and for which, for each
* a
* if an
** an
* an
** if a
***
** and that otherwise,
*** either
***
* its
* its
* if an
** either
**
If
| <code>Imports ''synonym'' = ''type''</code>
|-
Line 1,681 ⟶ 1,680:
| <code>''name'' = ''initial_value''</code>| <code>''name'' = ''initial_value''</code>
|-
| [[
| <code>''name'' = ''initial_value'';</code>
|
Line 1,687 ⟶ 1,686:
|-
| [[Fortran]]
| <code>''type'' :: ''name''</code>
| <code>''type'', PARAMETER :: ''name'' = ''value''</code>
|
Line 1,693 ⟶ 1,692:
| [[PHP]]
| <code>$''name'' = ''initial_value'';</code>
| <code>define("''name''", ''value'');<br
| rowspan=2 {{n/a}}
|-
Line 1,737 ⟶ 1,736:
| <code>val ''name'' «: ''type''» = ''value''</code>
|-
| [[
|
| <code>«''name''::''type'';» ''name'' = ''value''</code>
Line 1,761 ⟶ 1,760:
* {{note|variable types|b}}Types are just regular objects, so you can just assign them.
* {{note|Perl's my keyword|c}} In Perl, the "my" keyword scopes the variable into the block.
* {{note|ML ref|d}} Technically, this does not declare ''name'' to be a mutable variable—in ML, all names can only be bound once; rather, it declares ''name'' to point to a "reference" data structure, which is a simple mutable cell. The data structure can then be read and written to using the
* {{note|Ada declaration|e}} If no initial value is given, an invalid value is automatically assigned (which will trigger a run-time exception if it used before a valid value has been assigned). While this behaviour can be suppressed it is recommended in the interest of predictability. If no invalid value can be found for a type (for example in case of an unconstraint integer type), a valid, yet predictable value is chosen instead.
* {{note|Rust declaration|f}} In Rust, if no initial value is given to a
== [[Control flow]] ==
=== [[Conditional (programming)|Conditional]] statements ===
{| class="wikitable sortable"
|- valign="top"
Line 1,778 ⟶ 1,775:
|- valign="top"
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>if ''condition'' then{{indent|2}}''statements''<br
| <code>if ''condition{{sub|1}}'' then{{indent|2}}''statements''<br
| <code>case ''expression'' is{{indent|2}}when ''value_list''{{sub|1}} => ''statements''{{indent|2}}when ''value_list{{sub|2}}'' => ''statements''{{indent|2}}''...''{{indent|2}}«when others => ''statements''»<br
| <code>(if ''condition{{sub|1}}'' then{{indent|2}}''expression{{sub|1}}''<br
|- valign="top"
| [[Seed7]]
| <code>if ''condition'' then{{indent|2}}''statements''<br
| <code>if ''condition{{sub|1}}'' then{{indent|2}}''statements''<br
| <code>case ''expression'' of{{indent|2}}when ''set1'' : ''statements''{{indent|2}}''...''{{indent|2}}«otherwise: ''statements''»<br
|
|- valign="top"
| [[Modula-2]]
| <code>if ''condition'' then{{indent|2}}''statements''<br
| <code>if ''condition{{sub|1}}'' then{{indent|2}}''statements''<br
| rowspan=1 | <code>case ''expression'' of{{indent|2}}''caseLabelList'' : ''statements'' {{pipe}}{{indent|2}}''...''{{indent|2}}«else ''statements''»<br
|
|- valign="top"
Line 1,799 ⟶ 1,796:
| <code>if ''condition'' then ''statements'' elif ''condition'' then ''statements'' fi</code>
| <code>case ''switch'' in ''statements, statements«,...'' out ''statements''» esac</code>
| <syntaxhighlight lang="text" inline>( condition | valueIfTrue | valueIfFalse )</syntaxhighlight>
|- valign="top"
| [[ALGOL 68]]<br
| <syntaxhighlight lang="text" inline>( condition | statements «| statements» )</syntaxhighlight>
| <syntaxhighlight lang="text" inline>( condition | statements |: condition |
| <syntaxhighlight lang="text" inline>( variable | statements,... «| statements» )</syntaxhighlight>
|
|- valign="top"
| [[APL (programming language)|APL]]
| <code>:If ''condition''{{indent|2}}''instructions''<br
| <code>:If ''condition''{{indent|2}}''instructions''<br
| <code>:Select ''expression''{{indent|2}}:Case ''case1''{{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}«:Else{{indent|4}}''instructions''»<br
| <code>{''condition'':''valueIfTrue'' ⋄ ''valueIfFalse''}</code>
|- valign="top"
| [[C (programming language)|C]] ([[C99]])
| rowspan=7| <code>if (''condition'') ''instructions''<br
| rowspan=7| <code>if (''condition'') ''instructions''<br
| rowspan=7| <code>switch (''variable'') { {{indent|2}}case ''case1'': ''instructions'' «; break;»{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br
| rowspan=7| <code>''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''</code>
|- valign="top"
Line 1,832 ⟶ 1,829:
|- valign="top"
| [[C Sharp (programming language)|C#]]
| <code>if (''condition'') ''instructions''<br
| <code>if (''condition'') ''instructions''<br
| <code>switch (''variable'')<br
All non-empty cases must end with a
The
| <code>''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''</code>
|- valign="top"
| [[Windows PowerShell]]
| <code>if (''condition'') ''instruction''<br
| <code>if (''condition'') { ''instructions'' }<br
| <code>switch (''variable'') { ''case1''{''instructions'' «break;» } ''...'' «default { ''instructions'' }»}</code>
|
|- valign="top"
| [[Go (programming language)|Go]]
| <code>if ''condition'' {''instructions''}<br
| <code>if ''condition'' {''instructions''}<br
| <code>switch ''variable'' { {{indent|2}}case ''case<sub>1</sub>'': ''instructions''{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br
|
|- valign="top"
| [[Swift (programming language)|Swift]]
| <code>if ''condition'' {''instructions''}<br
| <code>if ''condition'' {''instructions''}<br
| <code>switch ''variable'' { {{indent|2}}case ''case<sub>1</sub>'': ''instructions''{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br
|
|- valign="top"
| [[Perl]]
| <code>if (''condition'') {''instructions''}<br
| <code>if (''condition'') {''instructions''}<br
| <code>use feature "switch";<br
| <code>''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''</code>
|- valign="top"
| [[Raku (programming language)|Raku]]
| <code>if ''condition'' {''instructions''}<br
| <code>if ''condition'' {''instructions''}
| <code>given ''variable'' { {{indent|2}}when ''case<sub>1</sub>'' { ''instructions'' }{{indent|2}}''...''{{indent|2}}«default { ''instructions'' }»<br
| <code>''condition'' [[?:|??]] ''valueIfTrue'' !! ''valueIfFalse''</code>
|- valign="top"
| [[Ruby (programming language)|Ruby]]
| <code>if ''condition''{{indent|2}}''instructions''<br
| <code>if ''condition''{{indent|2}}''instructions''<br
| <code>case ''variable''{{indent|2}}when ''case<sub>1</sub>''{{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}«else{{indent|4}}''instructions''»<br
| <code>''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''</code>
|- valign="top"
| [[Scala (programming language)|Scala]]
| <code>if (''condition'') {''instructions''}<br
| <code>if (''condition'') {''instructions''}<br
| <code>''expression'' match { {{indent|2}}case ''pattern1'' => ''expression''{{indent|2}}case ''pattern2'' => ''expression''{{indent|2}}''...''{{indent|2}}«case _ => ''expression''»<br
| <code>if (''condition'') ''valueIfTrue'' else ''valueIfFalse''</code>
|- valign="top"
| [[Smalltalk]]
| <code>''condition'' ifTrue:{{indent|2}}''trueBlock''<br
|
|
Line 1,889 ⟶ 1,886:
|- valign="top"
| [[Common Lisp]]
| <code>''(when'' condition{{indent|2}}''instructions'')</code><br
| <code>(cond (''condition1 instructions''){{indent|2}}(''condition2 instructions''){{indent|2}}''...''{{indent|2}}«(t ''instructions'')»)</code>
| <code>(case ''expression''{{indent|2}}(''case1 instructions''){{indent|2}}(''case2 instructions''){{indent|2}}''...''{{indent|2}}«(otherwise ''instructions'')»)</code>
| <code>(if ''test then else'')</code><br
|- valign="top"
| [[Scheme (programming language)|Scheme]]
| <code>(when ''condition instructions'')</code><br
| <code>(cond (''condition1 instructions'') (''condition2 instructions'') ''...'' «(else ''instructions'')»)</code>
| <code>(case (''variable'') ((''case1'') ''instructions'') ((''case2'') ''instructions'') ''...'' «(else ''instructions'')»)</code>
Line 1,907 ⟶ 1,904:
|- valign="top"
| [[Pascal (programming language)|Pascal]]
| <code>if ''condition'' then begin{{indent|2}}''instructions''<br
| <code>if ''condition'' then begin{{indent|2}}''instructions''<br
| <code>case ''variable'' of{{indent|2}}''case1'': ''instructions''{{indent|2}}''...''{{indent|2}}«else: ''instructions''»<br
|- valign="top"
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=3| <code>If ''condition'' Then{{indent|2}}''instructions''<br
| rowspan=3| <code>If ''condition'' Then{{indent|2}}''instructions''<br
| rowspan=3| <code>Select« Case» ''variable''{{indent|2}}Case ''case_pattern{{sub|1}}''{{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}«Case Else{{indent|4}}''instructions''»<br
| <code>[[IIf]](''condition'', ''valueIfTrue'', ''valueIfFalse'')</code>
|- valign="top"
Line 1,923 ⟶ 1,920:
|- valign="top"
| [[Python (programming language)|Python]]{{ref|python indent|[a]}}
| <code>if ''condition'' :<br
| <code>if ''condition'' :<br
| Python 3.10+:<br
| Python 2.5+:<br
|- valign="top"
| [[
| <code>if (''condition'') { ''instructions'' } «else { ''instructions'' }»</code>
| <code>if (''condition'') { ''instructions'' } else if (''condition'') { ''instructions'' } ''...'' «else { ''instructions'' }»</code>
Line 1,935 ⟶ 1,932:
|- valign="top"
| [[Fortran]]
| <code>IF (''condition'') THEN{{indent|2}}''instructions''<br
| <code>IF (''condition'') THEN{{indent|2}}''instructions''<br
| <code>SELECT CASE(''variable''){{indent|2}}CASE (''case1''){{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}CASE DEFAULT{{indent|4}}''instructions''<br
|
|- valign="top"
Line 1,943 ⟶ 1,940:
| <code>''condition'' IF ''instructions'' « ELSE ''instructions''» THEN</code>
| <code>''condition'' IF ''instructions'' ELSE ''condition'' IF ''instructions'' THEN THEN</code>
| <code>''value'' CASE{{indent|2}}''case'' OF ''instructions'' ENDOF{{indent|2}}''case'' OF ''instructions'' ENDOF{{indent|4}}''default instructions''<br
| <code>''condition'' IF ''valueIfTrue ''ELSE ''valueIfFalse'' THEN</code>
|- valign="top"
Line 1,955 ⟶ 1,952:
| Lightweight syntax mode:
Either on a single line or with indentation as shown below:
<code>if ''condition'' then<br
| Lightweight syntax mode:<br
|- valign="top"
| [[Standard ML]]
| <code>if ''condition'' then «(''»instructions «'')»<br
| <code>if ''condition'' then «(''»instructions «'')»<br
| <code>case ''value'' of{{indent|2}}''pattern1'' => ''expression''{{indent|2}}{{pipe}} ''pattern2'' => ''expression''{{indent|2}}''...''{{indent|2}}«{{pipe}} _ => ''expression»''</code>{{ref|pattern matching|[b]}}
|- valign="top"
| [[
| <code>if ''condition'' then ''expression'' else ''expression''</code><br
| <code>''result'' {{pipe}} ''condition'' = ''expression''{{indent|2}}{{pipe}} ''condition'' = ''expression''{{indent|2}}{{pipe}} otherwise = ''expression''</code>
| <code>case ''value'' of { {{indent|2}}''pattern1'' -> ''expression'';{{indent|2}}''pattern2'' -> ''expression'';{{indent|2}}''...''{{indent|2}}«_ -> ''expression»''<br
|- valign="top"
| [[Bash shell]]
| <code>if ''condition-command;'' then{{indent|2}}''expression''<br
| <code>if ''condition-command;'' then{{indent|2}}''expression''<br
| <code>case ''"$variable"'' in{{indent|2}}''"$condition1" ){{indent|4}}command...{{indent|2}}"$condition2" ){{indent|4}}command...''<br
|
|- valign="top"
| [[CoffeeScript]]
| <code>if ''condition'' then ''expression'' «else ''expression»''</code><br
| <code>if ''condition'' then ''expression'' else if ''condition'' then ''expression'' «else ''expression»''</code><br
| <code>switch ''expression''{{indent|2}}when ''condition'' then ''expression''{{indent|2}}else ''expression''</code><br
| All conditions are expressions.
|- valign="top"
| [[COBOL]]
| <code>IF ''condition'' «THEN»{{indent|2}}''expression''<br
|
| <code>EVALUATE ''expression'' «ALSO ''expression...''»{{indent|2}}WHEN ''case-or-condition'' «ALSO ''case-or-condition...»{{indent|4}}expression{{indent|2}}...''{{indent|2}}«WHEN OTHER{{indent|4}}''expression''»<br
|
|- valign="top"
| [[Rust (programming language)|Rust]]
| <code>if ''condition'' { {{indent|2}}''expression''<br
| <code>if ''condition'' { {{indent|2}}''expression''<br
| <code>match ''variable'' { {{indent|2}}''pattern1'' => ''expression,''{{indent|2}}''pattern2'' => ''expression,''{{indent|2}}''pattern3'' => ''expression,''{{indent|2}}«_ => ''expression''»<br
| All conditions are expressions
|- valign="top"
Line 2,003 ⟶ 2,000:
* {{note|pascal semicolon|c}} In languages of the Pascal family, the semicolon is not part of the statement. It is a separator between statements, not a terminator.
* {{note|COBOL END-IF|d}} <code>END-IF</code> may be used instead of the period at the end.
* {{note|Rust match expression|e}} In Rust, the comma (
=== [[Control flow#Loops|Loop statements]] ===
{| class="wikitable sortable"
|-
Line 2,016 ⟶ 2,012:
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>while ''condition'' loop
| <code>loop
| <code>for ''index'' in
| <code>for ''item'' of
|-
| rowspan=2| [[ALGOL 68]] || colspan=3 align=center| <code>
| rowspan=2| <code>for key
|-
| <code>
| <code>
| <code>
|-
| [[APL (programming language)|APL]]
| <code>:While ''
| <code>:Repeat
| <code>:For ''var«s»'' :In ''list''{{indent|2}}''statements''<br
| <code>:For ''var«s»'' :InEach ''list''{{indent|2}}''statements''<br
|-
| [[C (programming language)|C]] ([[C99]])
| rowspan=9|
| rowspan=9| <code>do ''
| rowspan=5| <code>for (''«type» i
| {{n/a}}
|-
| [[Objective-C]]
| <code>for (''type item
|-
| [[C++]] (STL)
| <code>«std::»for_each(''start'', ''
|-
| [[C Sharp (programming language)|C#]]
Line 2,052 ⟶ 2,048:
| <code>for (''type item'' : ''set'') ''instructions''</code>
|-
| [[
| <code>for (var ''i'' = ''first''; ''i'' <= ''last''; ''i''++) ''instructions''</code>
| Since [[EcmaScript]] 2015:<ref>{{cite web|url=https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/for...of|title=for...of|work=mozilla.org|access-date=30 January 2017}}</ref>
Line 2,058 ⟶ 2,054:
|-
| [[PHP]]
| <code>foreach (range(''first'', ''
| <code>foreach (''set'' as ''item'') ''instructions''</code><br
|-
| [[Windows PowerShell]]
| <code>for ($i = ''
| <code>foreach (''item'' in ''set'') ''instructions''</code>
|-
| [[D (programming language)|D]]
| <code>foreach ''(i;'' first ''...'' last
| <code>foreach ''
|-
| [[Go (programming language)|Go]]
| <code>for ''
|
| <code>for ''
| <code>for ''
|-
| [[Swift (programming language)|Swift]]
| <code>while ''
| 2.x:<br
| <code>for ''i'' = ''first'' ... ''last'' { ''instructions'' }
| <code>for ''
|-
| [[Perl]]
| <code>while (''condition'') { ''instructions'' }</code><br
| <code>do { ''instructions'' } while (''condition'')</code><br
| <code>for
| <code>for
|-
| [[Raku (programming language)|Raku]]
| <code>while ''condition'' { ''instructions'' }</code><br
| <code>repeat { ''instructions'' } while ''
| <code>for ''first''..''last'' -> $i { ''instructions'' }</code><br
| <code>for ''set«'' -> ''$item»'' { ''instructions'' }</code>
|-
| [[Ruby (programming language)|Ruby]]
| <code>while ''
| <code>begin
| <code>for i in ''
| <code>for ''item'' in ''set''{{indent|2}}''instructions''<br
|-
| [[Bash shell]]
| <code>while ''condition ;''do
| {{n/a}}
| <code>for ((''i'' = ''first''; ''i'' <= ''last''; ++''i'')) ; do
| <code>for ''item'' in ''set ;''do
|-
| [[Scala (programming language)|Scala]]
| <code>while (''condition'') { ''instructions'' }</code>
| <code>do { ''instructions'' } while (''condition'')</code>
| <code>for (''i'' <- ''first'' to ''last
| <code>for (''item'' <- ''set'') { ''instructions'' }</code><br
|-
| [[Smalltalk]]
| <code>''conditionBlock'' whileTrue:
| <code>''loopBlock'' doWhile:
| <code>''first'' to: ''last'' do:
| <code>''collection'' do:
|-
| [[Common Lisp]]
| <code>(loop
| <code>(loop
| <code>(loop
| <code>(loop
|-
| [[Scheme (programming language)|Scheme]]
| <code>(do () (''notcondition'') ''
| <code>{{codett|2=scheme|(let loop () (}}''instructions
| <code>(do ((i ''
| <code>{{codett|2=scheme|(for-each (lambda (}}''item'') ''
|-
| [[ISLISP]]
| <code>(while ''
| <code>{{codett|2=lisp|1=(tagbody loop}} ''instructions'' (if ''condition'' {{codett|2=lisp|1=(go loop))}}</code>
| <code>{{codett|2=lisp|1=(for ((i}} ''
| <code>{{codett|2=lisp|1=(mapc (lambda (}}''item'') ''
|-
| [[Pascal (programming language)|Pascal]]
| <code>while ''condition'' do begin
| <code>repeat
| <code>for ''i'' := ''first
| <code>for ''item'' in ''set'' do ''instructions''</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=2| <code>Do While ''
| rowspan=2| <code>Do
|
<code>For ''i'' = ''first'' To ''last'' «
| <code>For Each ''item'' In ''set''{{indent|2}}''instructions''<br
|-
| [[Visual Basic .NET]]
| rowspan=2| <code>For i
| rowspan=2| <code>For Each ''item«'' As ''
|-
| [[Xojo]]
| <code>While ''
| <code>Do Until ''
|-
| [[Python (programming language)|Python]]
| <code>while ''condition'' :
| {{n/a}}
| Python 3.x:<br
| <code>for ''item'' in ''set'':
|-
| [[
| <code>while (''condition'') { ''instructions'' }
| <code>do { ''instructions'' } while (''condition'')
| <code>for (i = ''
| <code>foreach ''item''(''set'')
|-
| [[Fortran]]
| <code>DO WHILE (''condition'')
| <code>DO
| <code>DO ''
| {{n/a}}
|-
| [[Forth (programming language)|Forth]]
| <code>BEGIN ''
| <code>BEGIN '' instructions condition
| <code>''limit start
| {{n/a}}
|-
Line 2,183 ⟶ 2,179:
| <code>while ''condition'' do ''instructions'' done</code>
| {{n/a}}
| <code>for i = ''
| <code>Array.iter (fun ''
|-
| [[F Sharp (programming language)|F#]]
| <code>while ''condition'' do
| {{n/a}}
| <code>for i = ''
| <code>for''
|-
| [[Standard ML]]
| <code>while ''condition'' do ( ''instructions'' )</code>
| colspan=2 {{n/a}}
| <code>Array.app (fn ''
|-
| [[
| colspan=2 {{n/a}}
| <code>Control.Monad.forM_ [''first''..''last''] (\i -> do ''
| <code>Control.Monad.forM_''
|-
| [[Eiffel (programming language)|Eiffel]]
| colspan=4| <code>from
|-
| [[CoffeeScript]]
| <code>while ''
| {{n/a}}
| <code>for ''i'' in [''first''..''last'']
| <code>for ''item'' in ''set''{{indent|2}}''expression''</code><br
|-
| [[COBOL]]
| <code>PERFORM ''procedure-1
| <code>PERFORM ''procedure-1
| <code>PERFORM ''procedure-1
| {{n/a}}
|-
| [[Rust (programming language)|Rust]]
| <code>while ''condition'' {
| <code>loop {
| <code>for i in ''
| <code>for ''item'' in ''set'' {
|}
* {{note|step|a}} "<code>step</code> n" is used to change the loop interval. If "<code>step</code>" is omitted, then the loop interval is 1.
* {{note|Ada_quantifiers|b}} This implements the [[universal quantifier]] ("for all" or
* {{note|COBOL THRU|c}} <code>THRU</code> may be used instead of <code>THROUGH</code>.
* {{note|COBOL GREATER THAN|d}}
* {{note|Rust FOREACH|e}} Type of set expression must implement trait <code>std::iter::IntoIterator</code>.
=== [[Exception handling|Exceptions]] ===
▲{{further|Exception handling syntax}}
{| class="wikitable sortable"
|-
Line 2,242 ⟶ 2,236:
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>raise ''exception_name
| <code>begin
| <code>{{codett|2=ada|1=pragma Assert}} (
|-
| [[APL (programming language)|APL]]
| <code>''«string_expression»'' ⎕SIGNAL ''number_expression''</code>
| <code>:Trap ''number«s»_expression''{{indent|2}}''statements''<br
| <code>''«string_expression»'' {{codett|⎕SIGNAL 98/⍨~|apl}}''condition''</code>
|-
| [[C (programming language)|C]] ([[C99]])
| <code>[[longjmp]](''state'', ''exception'');</code>
| <code>switch ([[setjmp]](''state'')) { case 0: ''
| rowspan=2|<code>assert(''condition'');</code>
|-
| [[C++]]
| rowspan=8|<code>throw ''
| <code>try { ''
|-
| [[C Sharp (programming language)|C#]]
| <code>try { ''
| <code>System.Diagnostics.Debug.Assert(''condition'');</code><br
|-
| [[Java (programming language)|Java]]
| <code>try { ''
| <code>assert ''
|-
| [[
| <code>try { ''
| {{dunno}}
|-
| [[D (programming language)|D]]
| <code>try { ''
| <code>assert(''condition'');</code>
|-
| [[PHP]]
| <code>try { ''
| <code>assert(''condition'');</code>
|-
| [[
| <code>try { ''
| {{dunno}}
|-
| [[Windows PowerShell]]
| <code>trap
| <code>{{codett|[Debug]::Assert(|ps1}}''condition'')</code>
|-
| [[Objective-C]]
| <code>@throw ''
| <code>@try { ''
| <code>NSAssert(''condition'', ''
|-
| [[Swift (programming language)|Swift]]
| <code>throw ''
| <code>do { try ''
| <code>assert(''condition''«, ''
|-
| [[Perl]]
| rowspan=2| <code>die ''
| <code>eval { ''
| {{dunno}}
|-
| [[Raku (programming language)|Raku]]
| <code>try { ''
| {{dunno}}
|-
| [[Ruby (programming language)|Ruby]]
| <code>raise ''
| <code>begin
|
|-
| [[Smalltalk]]
| <code>''exception
| <code>''instructionBlock'' on: ''exception'' do: ''handlerBlock''</code>
| <code>assert: ''
|-
| [[Common Lisp]]
| <code>(error ''
| <code>(handler-case
| <code>(assert ''
|-
| [[Scheme (programming language)|Scheme]] ([[R6RS|R<sup>6</sup>RS]])
| <code>(raise ''
| <code>(guard (con (''condition instructions'') ''
| {{dunno}}
|-
| [[ISLISP]]
| <code>(error ''
| <code>(with-handler
| {{dunno}}
|-
| [[Pascal (programming language)|Pascal]]
| <code>raise ''
| <code>try ''Except'' on ''E: exception'' do begin ''
| {{dunno}}
|-
| [[Visual Basic (classic)|Visual Basic]]
| <code>Err.Raise ''
| <code>{{codett|2=vbnet|With New}} ''
'*** Try class ***
Private mstrDescription As String
Line 2,355 ⟶ 2,349:
Public Property Get Description() As String
Description = mstrDescription
End Property</syntaxhighlight><ref>{{cite web|url=https://sites.google.com/site/truetryforvisualbasic/|title=Try-Catch for VB|work=google.com|access-date=30 January 2017|archive-date=16 April 2016|archive-url=https://web.archive.org/web/20160416093023/https://sites.google.com/site/truetryforvisualbasic/|url-status=dead}}</ref>
| <code>Debug.Assert ''
|-
| [[Visual Basic .NET]]
| <code>Throw ''
| <code>Try
| <code>System.Diagnostics.<wbr/
|-
| [[Xojo]]
| <code>Raise ''
| <code>Try
| {{n/a}}
|-
| [[Python (programming language)|Python]]
| <code>raise ''
| <code>try:
| <code>assert ''
|-
| [[Fortran]]
Line 2,377 ⟶ 2,371:
|-
| [[Forth (programming language)|Forth]]
| <code>''code
| <code>''xt
| {{n/a}}
|-
| [[OCaml]]
| rowspan=2| <code>raise ''
| <code>try ''expression'' with ''pattern'' -> ''expression ...''</code>
| rowspan=2| <code>assert ''
|-
| [[F Sharp (programming language)|F#]]
| <code>try ''expression'' with ''pattern'' -> ''expression ...''</code><br
|-
| [[Standard ML]]
| <code>raise ''
| <code>''expression'' handle ''pattern'' => ''expression ...''</code>
|
|-
| [[
| <code>throw ''exception''</code><br
| <code>catch ''tryExpression catchExpression''</code><br
| <code>assert ''
|-
| [[COBOL]]
| <code>{{codett|2=cobolfree|RAISE
| <code>{{codett|2=cobolfree|USE
| {{n/a}}
|-
Line 2,409 ⟶ 2,403:
|}
* {{note|common lisp restarts|a}} Common Lisp allows
* {{note|
=== Other control flow statements ===
{| class="wikitable sortable"
|-
Line 2,424 ⟶ 2,417:
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>exit ''«loop_name»
| {{n/a}}
| <code>''label'':</code>
| <code>goto ''
| {{n/a}}
|-
| [[ALGOL 68]]
| <code>''value'' exit
| <code>do ''statements;'' skip exit
|
| <code>go to ''label; ...''<br
| <code>yield
([[Callback (computer science)|Callback]])<ref>{{cite web|url=http://rosettacode.org/wiki/Prime_decomposition#ALGOL_68|title=Prime decomposition – Rosetta Code|work=rosettacode.org|access-date=30 January 2017}}</ref>
|-
Line 2,442 ⟶ 2,435:
| <code>:Continue</code>
| <code>''label'':</code>
| <code>→''label''</code><br
| {{n/a}}
|-
Line 2,449 ⟶ 2,442:
| rowspan=5| <code>continue;</code>
| rowspan=12| <code>''label'':</code>
| rowspan=5| <code>goto ''
| rowspan=4 {{n/a}}
|-
Line 2,459 ⟶ 2,452:
|-
| [[C Sharp (programming language)|C#]]
| <code>yield return ''
|-
| [[Java (programming language)|Java]]
| rowspan=2| <code>break ''
| rowspan=2| <code>continue ''
| rowspan=2 {{n/a}}
|
|-
| [[
| <code>yield ''
|-
| [[PHP]]
| <code>break ''
| <code>continue ''
| rowspan=3| <code>goto ''
| <code>yield ''
|-
| [[Perl]]
| rowspan=2| <code>last ''
| rowspan=2| <code>next ''
|
|-
Line 2,485 ⟶ 2,478:
|-
| [[Go (programming language)|Go]]
| <code>break ''
| <code>continue ''
| <code>goto ''
|
|-
| [[Swift (programming language)|Swift]]
| <code>break ''
| <code>continue ''
| {{n/a}}
|
|-
| [[Bash shell]]
| <code>break ''
| <code>continue ''
| {{n/a}}
| {{n/a}}
Line 2,504 ⟶ 2,497:
|-
| [[Common Lisp]]
| <code>(return)</code><br
|
| <code>(tagbody ''
| <code>(go ''
|
|-
Line 2,518 ⟶ 2,511:
|-
| [[ISLISP]]
| <code>(return-from ''
|
| <code>(tagbody ''
| <code>(go ''
|
|-
Line 2,527 ⟶ 2,520:
| colspan=2 {{n/a}}
| rowspan=2| <code>''label'':</code>{{ref|Pascal's declarations|[a]}}
| rowspan=2| <code>goto ''
| rowspan=4 {{n/a}}
|-
Line 2,535 ⟶ 2,528:
|-
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=3| <code>Exit ''
| {{n/a}}
| rowspan=3| <code>''label'':</code>
| rowspan=3| <code>GoTo ''
|-
| [[Xojo]]
| rowspan=2 |<code>Continue ''
|-
| [[Visual Basic .NET]]
| <code>Yield ''
|-
| [[Python (programming language)|Python]]
Line 2,550 ⟶ 2,543:
| <code>continue</code>
| colspan=2 {{n/a}}
| <code>yield ''
|-
| [[RPG IV]]
Line 2,559 ⟶ 2,552:
|
|-
| [[
| <code>break;</code>
| <code>continue;</code>
Line 2,569 ⟶ 2,562:
| <code>EXIT</code>
| <code>CYCLE</code>
|
| <code>GOTO ''
| {{n/a}}
|-
Line 2,581 ⟶ 2,574:
|-
| [[Windows PowerShell]]
| <code>break ''
| <code>continue</code>
|
Line 2,597 ⟶ 2,590:
|
|-
| [[
|
|-
| [[COBOL]]
| <code>EXIT PERFORM</code>
| <code>EXIT PERFORM CYCLE</code>
| <code>''label'' «
| <code>GO TO ''
| {{n/a}}
|}
Line 2,611 ⟶ 2,604:
== [[Subroutine|Function]]s ==
See ''[[
{{sort-under}}
▲See [[Reflection (computer science)|reflection]] for calling and declaring functions by strings.
{| class="wikitable sortable sort-under"▼
▲{| class="wikitable sortable"
|- valign="top"
!
Line 2,623 ⟶ 2,615:
|- valign="top"
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>
| <code>procedure
| <code>function
| {{n/a}}
|- valign="top"
| [[ALGOL 68]]
| <code>
| <code>proc ''foo
| <code>proc ''foo
| {{n/a}}
|- valign="top"
| [[APL (programming language)|APL]]
| <code>''«parameters»'' foo ''parameters''</code>
| <code>
| <code>
| {{n/a}}
|- valign="top"
| [[C (programming language)|C]] ([[C99]])
| rowspan=9| <code>''foo''(''«parameters»'')</code>
| rowspan="5" | <code>[[void type|void]] ''foo''(''«parameters»'') { ''instructions'' }</code>
| rowspan="5" | <code>''type'' ''foo''(''«parameters»'') { ''instructions ...'' return ''value''; }</code>
| rowspan=3| <code>''«global declarations»''<br
|- valign="top"
| [[Objective-C]]
Line 2,651 ⟶ 2,643:
|- valign="top"
| [[Java (programming language)|Java]]
| <code>{{codett|2=java|public static void main(String[] args)}} { ''instructions'' }</code><br
|- valign="top"
| [[D (programming language)|D]]
| <code>{{codett|2=d|int main(«char[][] args»)}} { ''instructions''}</code><br
|- valign="top"
| [[C Sharp (programming language)|C#]]
Line 2,661 ⟶ 2,653:
| Same as above; alternatively, if simple enough to be an expression:
<code>[[void type|void]] foo(''«parameters»'') => ''expression'';</code>
|
|- valign="top"
| [[
| <code>function foo(''«parameters»'') { ''instructions'' }</code><br
| <code>function foo(''«parameters»'') { ''instructions ...'' return ''value''; }</code>
| {{n/a}}
Line 2,680 ⟶ 2,672:
| [[Common Lisp]]
| rowspan=3| <code>(foo ''«parameters»'')</code>
| <code>([[defun]] foo (''«parameters»''){{indent|2}}''instructions'')</code><br
| <code>([[defun]] foo (''«parameters»''){{indent|2}}''...{{indent|2}}value'')</code>
| rowspan=3 {{n/a}}
|- valign="top"
| [[Scheme (programming language)|Scheme]]
| <code>(define (foo ''parameters'') ''instructions'')</code><br
| <code>(define (foo ''parameters'') ''instructions... return_value'')</code><br
|- valign="top"
| [[ISLISP]]
Line 2,694 ⟶ 2,686:
| [[Pascal (programming language)|Pascal]]
| <code>foo«(''parameters'')»</code>
| <code>procedure foo«(''parameters'')»; «forward;»{{ref|forward declaration|[a]}}<br
| <code>function foo«(''parameters'')»: ''type''; «forward;»{{ref|forward declaration|[a]}}<br
| <code>program ''name'';<br
|- valign="top"
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=3| <code>Foo(''«parameters»'')</code>
| rowspan=3| <code>Sub Foo«(''parameters'')»{{indent|2}}''instructions''<br
| <code>Function Foo«(''parameters'')»« As'' type»''{{indent|2}}''instructions''{{indent|2}}Foo = ''value''<br
| <code>Sub Main(){{indent|2}}''instructions''<br
|- valign="top"
| [[Visual Basic .NET]]
| rowspan=2| Same as above; alternatively:
<code>Function Foo«(''parameters'')»« As ''type»''{{indent|2}}''instructions''{{indent|2}}Return ''value''<br
| rowspan=2| <code>{{codett|2=vbnet|Sub Main(««ByVal »args() As String»)}}{{indent|2}}''instructions''<br
|- valign="top"
| [[Xojo]]
Line 2,713 ⟶ 2,705:
| [[Python (programming language)|Python]]
| <code>foo(''«parameters»'')</code>
| <code>def foo(''«parameters»''):<br
| <code>def foo(''«parameters»''):<br
| {{n/a}}
|- valign="top"
| [[
| <code>foo(''«parameters» «;qualifiers»'')</code>
| <code>define foo (''«parameters»'') { ''instructions'' }</code>
Line 2,724 ⟶ 2,716:
|- valign="top"
| [[Fortran]]
| <code>foo (''«arguments»'')<br
| <code>SUBROUTINE sub_foo (''«arguments»''){{indent|2}}''instructions<br
| <code>''type'' FUNCTION foo (''«arguments»''){{indent|2}}''instructions''{{indent|2}}''...''{{indent|2}}''foo'' = ''value''<br
| <code>PROGRAM ''main''{{indent|2}}''instructions''<br
|- valign="top"
| [[Forth (programming language)|Forth]]
| <code>''«parameters» ''FOO</code>
| <code>{{codett|2=forth|: FOO « stack effect comment:}} ('' before'' -- ) »{{indent|2}}''instructions''<br
| <code>{{codett|2=forth|: FOO « stack effect comment:}} ('' before'' -- ''after'' ) »{{indent|2}}''instructions''<br
| {{n/a}}
|- valign="top"
Line 2,742 ⟶ 2,734:
|- valign="top"
| [[Perl]]
| <code>foo(''«parameters»'')</code><br
| <code>{{codett|2=perl|sub foo { «my (}}''parameters'') = @_;» ''instructions ''}</code>
| <code>{{codett|2=perl|sub foo { «my (}}''parameters'') = @_;» ''instructions''... «return» ''value''; }</code>
|- valign="top"
| [[Raku (programming language)|Raku]]
| <code>foo(''«parameters»'')</code><br
| <code>{{codett|2=raku|«multi »sub foo(}}''parameters'') { ''instructions'' }</code>
| <code>«our «''
|- valign="top"
| [[Ruby (programming language)|Ruby]]
| <code>foo«(''parameters'')»</code>
| <code>def foo«(''parameters'')»{{indent|2}}''instructions''<br
| <code>def foo«(''parameters'')»{{indent|2}}''instructions''{{indent|2}}«return» ''value''<br
|- valign="top"
| [[Rust (programming language)|Rust]]
Line 2,766 ⟶ 2,758:
| <code>def ''foo''«(''parameters'')»«: Unit =» { ''instructions'' }</code>
| <code>def ''foo''«(''parameters'')»«: ''type»'' = { ''instructions ...'' «return» ''value'' }</code>
| <code>{{codett|2=scala|1=def main(args: Array[String])}} { ''instructions'' }</code>
|- valign="top"
| [[Windows PowerShell]]
| <code>foo ''«parameters»''</code>
| <code>function ''foo'' { ''instructions'' };</code><br
| <code>function ''foo'' «(''parameters'')» { ''instructions
| rowspan=4 {{n/a}}
|- valign="top"
| rowspan=2| [[Bash shell]]
| rowspan=2| <code>foo ''«parameters»''</code>
| <code>function foo {{{indent|2}}''instructions''<br
| <code>function foo {{{indent|2}}''instructions''{{indent|2}}return ''«exit_code»''<br
|- valign="top"
| colspan=2|
Line 2,793 ⟶ 2,785:
|- valign="top"
| [[F Sharp (programming language)|F#]]
| <code>{{codett|2=f#|[<EntryPoint>] let main args}} ='' instructions''</code>
|- valign="top"
| [[Standard ML]]
Line 2,800 ⟶ 2,792:
|
|- valign="top"
| [[
| <code>foo ''parameters'' = do<br
| <code>foo ''parameters'' = ''return_value''</code><br
| <code>«main :: IO ()»<br
|- valign="top"
| [[Eiffel (programming language)|Eiffel]]
Line 2,813 ⟶ 2,805:
| rowspan=2| [[CoffeeScript]]
| <code>foo()</code>
|
| <code>{{codett|2=coffeescript|1=foo =
| rowspan=2 {{n/a}}
|- valign="top"
| <code>foo ''parameters''</code>
|
| <code>foo = ( ''parameters'' ) <nowiki>-></nowiki> ''value''</code>
|- valign="top"
| rowspan=2 | [[COBOL]]
| <code>CALL "''foo''" «USING ''parameters»{{indent|2}}«exception-handling»<br
| <code>«IDENTIFICATION DIVISION.»<br
| rowspan=2 | <code>«IDENTIFICATION DIVISION.»<br
| rowspan=2 {{n/a}}
|-
Line 2,831 ⟶ 2,823:
|}
* {{note|forward declaration|a}} Pascal requires "
* {{note|root class and feature|b}} Eiffel allows the specification of an application's root class and feature.
* {{note|Fortran arguments|c}} In Fortran, function/subroutine parameters are called arguments (since
* {{note|COBOL calling programs|d}} Instead of using
== [[Type conversion]]s{{anchor|Data conversions}} ==
Where ''string'' is a signed decimal number:
{| class="wikitable sortable sort-under"▼
▲{| class="wikitable sortable"
|-
!
Line 2,859 ⟶ 2,849:
| colspan=5 align=center| With prior declarations and association of: <code>string ''buf := "12345678.9012e34 ";'' file ''proxy; associate(proxy, buf);''</code>
|-
|
|
|
|
|
|-
|
|
|
|
|
|-
| [[APL (programming language)|APL]]
Line 2,889 ⟶ 2,879:
| <code>''long'' = [''string'' longLongValue];</code>
| <code>''float'' = [''string'' doubleValue];</code>
| <code>''string'' = {{codett|2=objc|[NSString stringWithFormat
| <code>''string'' = {{codett|2=objc|[NSString stringWithFormat
|-
| [[C++]] (STL)
Line 2,911 ⟶ 2,901:
| <code>''integer'' = std.conv.to!int<wbr/>(''string'')</code>
| <code>''long'' = std.conv.to!long<wbr/>(''string'')</code>
| <code>''float'' = std.conv.to!float<wbr/>(''string'')</code><br
| colspan=2| <code>''string'' = std.conv.to!string<wbr/>(''number'')</code>
|-
Line 2,917 ⟶ 2,907:
| <code>''integer'' = Integer.parseInt<wbr/>(''string'');</code>
| <code>''long'' = Long.parseLong<wbr/>(''string'');</code>
| <code>''float'' = Float.parseFloat<wbr/>(''string'');</code><br
| <code>''string'' = Integer.toString<wbr/>(''integer'');</code><br
| <code>''string'' = Float.toString<wbr/>(''float'');</code><br
|-
| [[
| colspan=2| <code>''integer'' = parseInt(''string'');</code>
| <code>''float'' = parseFloat(''string'');</code><br
| colspan=2| <code>''string'' = ''number''.toString ();</code><br
|-
| [[Go (programming language)|Go]]
| <code>''integer'', ''error'' = strconv.Atoi(''string'')<br
| <code>''long'', ''error'' = strconv.ParseInt<wbr/>(''string'', 10, 64)</code>
| <code>''float'', ''error'' = strconv.ParseFloat<wbr/>(''string'', 64)</code>
| <code>''string'' = strconv.Itoa(''integer'')</code><br
| <code>''string'' = strconv.FormatFloat<wbr/>(''float'')</code><br
|-
| [[Rust (programming language)|Rust]]{{ref|Rust type conversion|[d]}}
| <code>''string''.parse::<i32>()</code><br
| <code>''string''.parse::<i64>()</code><br
| <code>''string''.parse::<f64>()</code><br
| <code>''integer''.to_string()</code>
| <code>''float''.to_string()</code>
Line 2,964 ⟶ 2,954:
| <code>''integer'' = CInt(''string'')</code>
| <code>''long'' = CLng(''string'')</code>
| <code>''float'' = CSng(''string'')<br
| <code>''string'' = CStr(''number'')</code>
|
|-
| [[Visual Basic .NET]]<br
| <code>''integer'' = Integer.Parse<wbr />(''string'')</code>
| <code>''long'' = Long.Parse<wbr />(''string'')</code>
| <code>''float'' = Single.Parse<wbr />(''string'')</code><br
| colspan="2" | <code>''string'' ='' number''<wbr />.ToString()</code>
|-
Line 2,977 ⟶ 2,967:
| <code>''integer'' = Val(''string'')</code>
| <code>''long'' = Val(''string'')</code>
| <code>''double'' = Val(''string'')</code><br
| colspan=2| <code>''string'' = CStr(''number'')</code><br
|-
| [[Python (programming language)|Python]]
Line 2,986 ⟶ 2,976:
| colspan=2| <code>''string'' = str(''number'')</code>
|-
| [[
| <code>''integer'' = [[atoi]](''string'');</code>
| <code>''long'' = [[atol (programming)|atol]](''string'');</code>
Line 2,997 ⟶ 2,987:
|-
| [[PHP]]
| colspan=2| <code>''integer'' = intval(''string'');</code><br
| <code>''float'' = floatval(''string'');</code><br
| colspan=2| <code>''string'' = "''$number''";</code><br
|-
| [[Perl]]{{ref|Perl's technicalities|[b]}}
Line 3,010 ⟶ 3,000:
|-
| [[Ruby (programming language)|Ruby]]
| colspan=2| <code>''integer'' = ''string''.to_i</code><br
| <code>''float'' = ''string''.to_f</code><br
| colspan=2| <code>''string'' = ''number''.to_s</code>
|-
Line 3,029 ⟶ 3,019:
| <code>''long'' = [long]''string''</code>
| <code>''float'' = [float]''string''</code>
| colspan=2| <code>''string'' = [string]''number'';</code><br
|-
| [[OCaml]]
Line 3,051 ⟶ 3,041:
| <code>val ''string'' = Real<wbr/>.toString ''float''</code>
|-
| [[
| colspan=3| <code>''number'' = read ''string''</code>
| colspan=2| <code>''string'' = show ''number''</code>
|-
| [[COBOL]]
| colspan=3 | <code>{{codett|2=cobolfree|MOVE «FUNCTION» NUMVAL(}}''string''){{ref|COBOL's NUMVAL alternatives|[c]}} TO ''number''</code>
| colspan=2 | <code>MOVE ''number'' TO ''numeric-edited''</code>
|-
Line 3,063 ⟶ 3,053:
* {{note|JavaScript's technicalities|a}} JavaScript only uses floating point numbers so there are some technicalities.<ref name="Javascript numbers" />
* {{note|Perl's technicalities|b}} Perl doesn't have separate types. Strings and numbers are interchangeable.
* {{note|COBOL's NUMVAL alternatives|c}}
* {{note|Rust type conversion}} [https://doc.rust-lang.org/stable/std/primitive.str.html#method.parse
== [[Standard streams|Standard stream I/O]] ==
{| class="wikitable sortable"
|-
Line 3,084 ⟶ 3,073:
|-
| [[ALGOL 68]]
| <code>readf((''$format$'', ''x''));</code><br
| <code>[[printf]]((''$format$'', ''x''));</code><br
| <code>putf(stand error, (''$format$'', ''x''));</code>{{ref|ALGOL Unformatted|[a]}}
|-
Line 3,094 ⟶ 3,083:
|-
| [[C (programming language)|C]] ([[C99]])
| <code>[[scanf]](''format'', &''x'');</code><br
| <code>[[printf]](''format'', ''x'');</code><br
| <code>[[fprintf]](stderr, ''format'', ''x'');</code>{{ref|more c error output|[d]}}
|-
Line 3,104 ⟶ 3,093:
|-
| [[C++]]
| <code>[[iostream|«std::»cin]] >> ''x'';</code><br
| <code>[[iostream|«std::»cout]] << ''x'';</code>
| <code>[[iostream|«std::»cerr]] << ''x'';</code><br
|-
| [[C Sharp (programming language)|C#]]
| <code>''x'' = Console.Read();</code><br
| <code>Console.Write(''«format'', »''x'');</code><br
| <code>Console.Error<wbr/>.Write(''«format'', »''x'');</code><br
|-
| [[D (programming language)|D]]
| <code>''x'' = std.stdio.readln()</code>
| <code>std.stdio.write(''x'')</code><br
| <code>stderr.write(''x'')</code><br
|-
| [[Java (programming language)|Java]]
| <
| <code>System.out.print(''x'');</code><br
| <code>System.err.print(''x'');</code><br
|-
| [[Go (programming language)|Go]]
| <code>fmt.Scan(&''x'')</code><br
| <code>fmt.Println(''x'')</code><br
| <code>fmt.Fprintln(os{{Not a typo|.}}Stderr,
|-
| [[Swift (programming language)|Swift]]
| <code>''x'' = readLine()</code> (2.x)
| <code>print(''x'')</code> (2.x)<br
|
|-
| [[
|
| <code>document.write(''x'')</code>
|
|-
| [[
|
| <code>Response.Write(''x'')</code>
|
|-
| [[
| <code>''x'' = WScript.StdIn.Read(''chars'')</code><br
| <code>WScript.Echo(''x'')</code><br
| <code>WScript.StdErr.Write(''x'')</code><br
|-
| [[Common Lisp]]
| <
| <code>(princ ''x'')</code><br
| <
|-
| [[Scheme (programming language)|Scheme]] ([[R6RS|R<sup>6</sup>RS]])
| <
| <code>(display ''x'')</code><br
| <
|-
| [[ISLISP]]
| <code>(setf
| <code>{{codett|(format (standard-output)|lisp}} ''format x'')</code>
| <code>{{codett|(format (error-output)|lisp}} ''format x'')</code>
|-
| [[Pascal (programming language)|Pascal]]
| <code>read(''x'');</code><br
| <code>write(''x'');</code><br
| <code>write(stderr, ''x'');</code><br
|-
| [[Visual Basic (classic)|Visual Basic]]
| <code>Input« ''prompt'',» ''x''</code>
| <code>Print ''x''</code><br
| {{n/a}}
|-
| [[Visual Basic .NET]]
| <code>''x'' = Console.Read()</code><br
| <code>Console.Write(''«format'',»''x'')</code><br
| <code>Console.Error<wbr/>.Write(''«format'', ''»x'')</code><br
|-
| [[Xojo]]
| <code>''x'' = StandardInputStream.Read()</code><br
| <code>StandardOutputStream.Write(''x'')</code><br
| <code>StdErr.Write(''x'')</code><br
|-
| [[Python (programming language)|Python]] 2.x
| <code>''x'' = raw_input(''«prompt»'')</code>
| <code>print ''x''</code><br
| <code>{{codett|print >> sys.stderr,|python2}} ''x''</code><br
|-
| [[Python (programming language)|Python]] 3.x
Line 3,193 ⟶ 3,182:
| <code>print(''x«'', end=""», file=sys.stderr)</code>
|-
| [[
| <code>[[fgets]] (&''x'', stdin)</code>
| <code>[[fputs]] (''x'', stdout)</code>
Line 3,199 ⟶ 3,188:
|-
| [[Fortran]]
| <code>READ(*,''format'') ''variable names'' </code><br
| <code>WRITE(*,''format'') ''expressions'' </code><br
| <code>WRITE(ERROR_UNIT,''format'') ''expressions''</code>{{ref|Fortran standard units|[e]}}
|-
| [[Forth (programming language)|Forth]]
| <code>''buffer length'' ACCEPT ''( # chars read )''<br
| <code>''buffer length'' TYPE<br
| {{n/a}}
|-
| [[PHP]]
| <code>''$x'' = [[fgets]](STDIN);</code><br
| <code>print ''x'';</code><br
| <code>[[fprintf]](STDERR, ''format'', ''x'');</code>
|-
| [[Perl]]
| <code>''$x'' = <>;</code><br
| <code>print ''x'';</code><br
| <code>print STDERR ''x'';</code><br
|-
| [[Raku (programming language)|Raku]]
| <
| <code>''x''.print</code><br
| <code>''x''.note</code><br
|-
| [[Ruby (programming language)|Ruby]]
| <code>''x'' = gets</code>
| <code>puts ''x''</code><br
| <code>$stderr.puts(
|-
| [[Windows PowerShell]]
| <code>''$x'' = Read-Host«« -Prompt» ''text''»;</code><br
| <code>''x'';</code><br
| <code>Write-Error ''x''</code>
|-
| [[OCaml]]
| <code>let ''x'' = read_int ()</code><br
| <code>print_int ''x''</code><br
| <code>prerr_int ''x''</code><br
|-
| [[F Sharp (programming language)|F#]]
| <
| <code>[[printf]] ''format x ...''</code><br
| <code>[[fprintf|eprintf]] ''format x ...''</code><br
|-
| [[Standard ML]]
| <
| <code>print ''str''</code>
| <code>{{codett|TextIO.output (TextIO.stdErr,|sml}}'' str'')</code>
|-
| [[
| <code>''x'' <- readLn</code><br
| <code>print ''x''</code><br
| <code>hPrint stderr ''x''</code><br
|-
| [[COBOL]]
Line 3,267 ⟶ 3,256:
== Reading [[command-line argument]]s ==
{| class="wikitable sortable"
|-
Line 3,301 ⟶ 3,289:
| first argument
|-
| [[
| <code>WScript.Arguments(''n'')</code>
| <code>WScript.Arguments.length</code>
| <code>WScript.ScriptName</code><br
|-
| [[Go (programming language)|Go]]
Line 3,312 ⟶ 3,300:
|-
| [[Rust (programming language)|Rust]]{{ref|Rust args|[a]}}
| <code>std::env::args().nth(''n'')</code><br
|
|
|-
| [[Swift (programming language)|Swift]]
| <code>Process.arguments[''n'']</code> or<br
| <code>Process.arguments.count</code> or<br
| first argument
|-
Line 3,327 ⟶ 3,315:
|-
| [[Scheme (programming language)|Scheme]] ([[R6RS|R<sup>6</sup>RS]])
| {{code|2=lisp|(list-ref (command-line) n)
| {{code|2=lisp|(length (command-line))
| first argument
|-
Line 3,349 ⟶ 3,337:
| <code>CmdArgs(''n'')</code>
| <code>CmdArgs.Length</code>
|
|-
| [[Xojo]]
Line 3,361 ⟶ 3,349:
| first argument
|-
| [[
| <code>__argv[''n'']</code>
| <code>__argc</code>
Line 3,367 ⟶ 3,355:
|-
| [[Fortran]]
| <code>DO ''i'' = ''1'',''argc''{{indent|2}}CALL GET_COMMAND_ARGUMENT (''i'',''argv(i)'')<br
| <code>''argc'' = COMMAND_ARGUMENT_COUNT ()</code>
| <code>CALL GET_COMMAND_ARGUMENT (''0'',''progname'')</code>
Line 3,377 ⟶ 3,365:
|-
| [[Bash shell]]
| <code>$''n'' ($1, $2, $3, ''...'')</code><br
| <code>$#</code>
| <code>$0</code>
Line 3,383 ⟶ 3,371:
| [[Perl]]
| <code>$ARGV[''n'']</code>
|
| <code>$0</code>
|-
| [[Raku (programming language)|Raku]]
| <code>@*ARGS[''n'']</code>
|
| <code>$PROGRAM_NAME</code>
|-
Line 3,412 ⟶ 3,400:
|-
| [[Standard ML]]
|
|
|
|-
| [[
| {{code|lang=haskell|do { args <- System.getArgs; return length args !! n }}}
| {{code|lang=haskell|do { args <- System.getArgs; return length args }}}
Line 3,426 ⟶ 3,414:
|}
* {{note|Rust args|a}} In Rust,
* {{note|unseparated|b}} In Visual Basic, command-line arguments are not separated. Separating them requires a split function <code>Split(''string'')</code>.
* {{note|COBOL Arguments|c}} The COBOL standard includes no means to access command-line arguments, but common compiler extensions to access them include defining parameters for the main program or using
== Execution of commands ==
{| class="wikitable sortable"
!
Line 3,444 ⟶ 3,431:
| rowspan=3| <code>[[system (C standard library)|system]]("''command''");</code>
|
| rowspan=2| <code>[[Exec (operating system)|execl]](''path'', ''args'');</code><br
|-
| [[C++]]
Line 3,450 ⟶ 3,437:
|-
| [[Objective-C]]
|
|
|-
Line 3,489 ⟶ 3,476:
| [[Java (programming language)|Java]]
|
| <code>Runtime.exec(''command'');</code><br
|
|-
| [[
| <code>{{codett|WScript.CreateObject ("WScript.Shell").Run(|js}}''command'' «, ''WindowStyle''» «, ''isWaitOnReturn''»);</code>
| <code>WshShell.Exec(command)</code>
|
Line 3,518 ⟶ 3,505:
|-
| [[OCaml]]
| <code>Sys.command ''command
| <code>Unix.create_process ''prog args new_stdin new_stdout new_stderr, ...''</code>
| <code>Unix.execv ''prog args''</code><br
|-
| [[Standard ML]]
Line 3,527 ⟶ 3,514:
| <code>Posix.Process.exec (''path'', ''args'')</code>
|-
| [[
| <code>System.system ''command''</code>
| <code>System.Process<wbr/>.runProcess ''path args ...''</code>
Line 3,533 ⟶ 3,520:
|-
| [[Perl]]
| <code>system(''command'')</code><br
|
| <code>exec(''path'', ''args'')</code>
|-
| [[Ruby (programming language)|Ruby]]
| <code>system(''command'')</code><br
|
| <code>exec(''path'', ''args'')</code>
|-
| [[PHP]]
| <code>system(''command'')</code><br
|
|
|-
| [[Python (programming language)|Python]]
| <code>os.system(''command'')</code><br
| <code>subprocess.call(''["program", "arg1", "arg2", ...]'')</code>
| <code>os.execv(''path'', ''args'')</code>
|-
| [[
| <code>system(''command'')</code>
|
Line 3,563 ⟶ 3,550:
|-
| [[Windows PowerShell]]
|
| <code>«Invoke-Item »''program arg1 arg2 ...''</code>
|
|-
| [[Bash shell]]
| <code>''output''=`''command''`</code><br
|
|
|}
{{note|Fortran 2008|a}} Fortran 2008 or newer.<ref>{{cite web|url=https://gcc.gnu.org/onlinedocs/gfortran/EXECUTE_005fCOMMAND_005fLINE.html|title=EXECUTE_COMMAND_LINE – The GNU Fortran Compiler|work=gnu.org|access-date=30 January 2017}}</ref>
==See also==
* [[List of open-source programming languages]]
== References ==
|