Comparison of programming languages (basic instructions): Difference between revisions

Content deleted Content added
m Functions: {{codett}}
 
Line 1:
{{Short description|None}}
{{Refimprove|date=February 2009}}
{{ProgLangCompare}}
This article compares a large number of [[programming language]]s by tabulating their [[data type]]s, their [[Expression (computer science)|expression]], [[Statement (computer science)|statement]], and [[Declaration (computer programming)|declaration]] [[Syntax (programming languages)|syntax]], and some common operating-system interfaces.
__TOC__
 
== DataConventions typesof this article ==
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.
How to declare variable ''x'' as the following types:
 
The tables are not sorted lexicographically ascending by programming language name by default<!-- though this would be ideal -->, and that some languages have entries in some tables but not others.
{| class="wikitable"
{{Clear}}
 
== Type identifiers ==
=== [[Integer (computer science)|Integer]]s ===
{| class="wikitable sortable"
! rowspan=2|
! colspan=2| 8 bit ([[byte]])
! colspan=2| 16 bit ([[short integer]])
! colspan=2| 32 bit
! colspan=2| 64 bit ([[long integer]])
! colspan=2| Word size
! rowspan=2| Arbitrarily precise ([[Arbitrary-precision arithmetic|bignum]])
|-
! Signed
! Unsigned
! Signed
! Unsigned
! Signed
! Unsigned
! Signed
! Unsigned
! Signed
! Unsigned
|-
| [[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]}}
| <code>Integer</code>{{ref|Ada_range|[j]}}
| {{code|range 0 .. 2**Integer'Size - 1|ada}}{{ref|Ada_range|[j]}} or {{code|mod Integer'Size|ada}}{{ref|Ada_mod|[k]}}
| {{n/a}}
|-
| rowspan=2| [[ALGOL 68]] (variable-width)
| rowspan=2| <code>short short int</code>{{ref|CInt|[c]}}
| rowspan=2 {{n/a}}
| rowspan=2| <code>short int</code>{{ref|CInt|[c]}}
| rowspan=2 {{n/a}}
| rowspan=2| <code>int</code>{{ref|CInt|[c]}}
| rowspan=2 {{n/a}}
| rowspan=2| <code>long int</code>{{ref|CInt|[c]}}
| rowspan=2 {{n/a}}
| <code>int</code>{{ref|CInt|[c]}}
| {{n/a}}
| rowspan=2| <code>long long int</code>{{ref|a68|[a]}}{{ref|a68g|[g]}}
|-
| colspan=2 align=center|<code>bytes</code> and <code>bits</code>
|-
| [[C (programming language)|C]] ([[C99]] fixed-width)
| rowspan=2| <code>int8_t</code>
| rowspan=2| <code>uint8_t</code>
| rowspan=2| <code>int16_t</code>
| rowspan=2| <code>uint16_t</code>
| rowspan=2| <code>int32_t</code>
| rowspan=2| <code>uint32_t</code>
| rowspan=2| <code>int64_t</code>
| rowspan=2| <code>uint64_t</code>
| rowspan=2| <code>intptr_t</code>{{ref|CInt|[c]}}
| rowspan=2| <code>size_t</code>{{ref|CInt|[c]}}
| rowspan=5 {{n/a}}
|-
| [[C++]] ([[C++11]] fixed-width)
|-
| [[C (programming language)|C]] ([[C99]] variable-width)
| rowspan=2| <code>signed char</code>
| rowspan=2| <code>unsigned char</code>
| rowspan=2| <code>short</code>{{ref|CInt|[c]}}
| rowspan=2| <code>unsigned short</code>{{ref|CInt|[c]}}
| rowspan=2| <code>long</code>{{ref|CInt|[c]}}
| rowspan=2| <code>unsigned long</code>{{ref|CInt|[c]}}
| rowspan=2| <code>long long</code>{{ref|CInt|[c]}}
| rowspan=2| <code>unsigned long long</code>{{ref|CInt|[c]}}
| rowspan=2| <code>int</code>{{ref|CInt|[c]}}
| rowspan=2| <code>unsigned int</code>{{ref|CInt|[c]}}
|-
| [[C++]] ([[C++11]] variable-width)
|-
| [[Objective-C]] ([[Cocoa (API)|Cocoa]])
| <code>signed char</code> or <code>int8_t</code>
| <code>unsigned char</code> or <code>uint8_t</code>
| <code>short</code> or <code>int16_t</code>
| <code>unsigned short</code> or <code>uint16_t</code>
| <code>int</code> or <code>int32_t</code>
| <code>unsigned int</code> or <code>uint32_t</code>
| <code>long long</code> or <code>int64_t</code>
| <code>unsigned long long</code> or <code>uint64_t</code>
| <code>NSInteger</code> or <code>long</code>
| <code>NSUInteger</code> or <code>unsigned long</code>
|-
| [[C Sharp (programming language)|C#]]
| <code>sbyte</code>
| <code>byte</code>
| rowspan=2| <code>short</code>
| <code>ushort</code>
| rowspan=2| <code>int</code>
| <code>uint</code>
| rowspan=2| <code>long</code>
| <code>ulong</code>
| <code>IntPtr</code>
| <code>UIntPtr</code>
| <code>System.Numerics.<wbr/>BigInteger</code><br/>(.NET 4.0)
|-
| [[Java (programming language)|Java]]
| <code>byte</code>
| {{n/a}}
| <code>char</code>{{ref|Java char|[b]}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| <code>java.math.<wbr/>BigInteger</code>
|-
| [[Go (programming language)|Go]]
| <code>int8</code>
| <code>uint8</code> or <code>byte</code>
| <code>int16</code>
| <code>uint16</code>
| <code>int32</code>
| <code>uint32</code>
| <code>int64</code>
| <code>uint64</code>
| <code>int</code>
| <code>uint</code>
| <code>big.Int</code>
|-
| [[Rust (programming language)|Rust]]
| <code>i8</code>
| <code>u8</code>
| <code>i16</code>
| <code>u16</code>
| <code>i32</code>
| <code>u32</code>
| <code>i64</code>
| <code>u64</code>
| <code>isize</code>
| <code>usize</code>
| {{n/a}}
|-
| [[Swift (programming language)|Swift]]
| <code>Int8</code>
| <code>UInt8</code>
| <code>Int16</code>
| <code>UInt16</code>
| <code>Int32</code>
| <code>UInt32</code>
| <code>Int64</code>
| <code>UInt64</code>
| <code>Int</code>
| <code>UInt</code>
|-
| [[D (programming language)|D]]
| <code>byte</code>
| <code>ubyte</code>
| <code>short</code>
| <code>ushort</code>
| <code>int</code>
| <code>uint</code>
| <code>long</code>
| <code>ulong</code>
| {{n/a}}
| {{n/a}}
| <code>BigInt</code>
|-
| [[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>
| <code>(signed-byte 8)</code>
| <code>(unsigned-byte 8)</code>
| <code>(signed-byte 16)</code>
| <code>(unsigned-byte 16)</code>
| <code>(signed-byte 32)</code>
| <code>(unsigned-byte 32)</code>
| <code>(signed-byte 64)</code>
| <code>(unsigned-byte 64)</code>
|
|
| <code>bignum</code>
|-
| [[Scheme (programming language)|Scheme]]
|
|
|
|
|
|
|
|
|
|
|
|-
| [[ISLISP]]<ref name="Specification">{{cite web|url=http://www.islisp.info/specification.html|title=www.islisp.info: Specification|work=islisp.info|access-date=30 January 2017|archive-url=https://web.archive.org/web/20160122121427/http://islisp.info/specification.html|archive-date=22 January 2016|url-status=dead}}</ref>
|
|
|
|
|
|
|
|
|
|
| <code>bignum</code>
|-
| [[Pascal (programming language)|Pascal]] ([[Free Pascal|FPC]])
| <code>shortint</code>
| <code>byte</code>
| <code>smallint</code>
| <code>word</code>
| <code>longint</code>
| <code>longword</code>
| <code>int64</code>
| <code>qword</code>
| <code>integer</code>
| <code>cardinal</code>
| {{n/a}}
|-
| [[Visual Basic (classic)|Visual Basic]]
| {{n/a}}
| rowspan=2|<code>Byte</code>
| <code>Integer</code>
| {{n/a}}
| <code>Long</code>
| {{n/a}}
| colspan=2 {{n/a}}
| rowspan=2 colspan=2 {{n/a}}
| rowspan=1 {{n/a}}
|-
| [[Visual Basic .NET]]
| <code>SByte</code>
| <code>Short</code>
| <code>UShort</code>
| <code>Integer</code>
| <code>UInteger</code>
| <code>Long</code>
| <code>ULong</code>
| <code>System.Numerics<wbr/>.BigInteger</code><br/>(.NET 4.0)
|-
| [[FreeBasic]]
| <code>Byte</code> or <code><nowiki>Integer<8></nowiki></code>
| <code>UByte</code> or <code><nowiki>UInteger<8></nowiki></code>
| <code>Short</code> or <code><nowiki>Integer<16></nowiki></code>
| <code>UShort</code> or <code><nowiki>UInteger<16></nowiki></code>
| <code>Long</code> or <code><nowiki>Integer<32></nowiki></code>
| <code>ULong</code> or <code><nowiki>UInteger<32></nowiki></code>
| <code>LongInt</code> or <code><nowiki>Integer<64></nowiki></code>
| <code>ULongInt</code> or <code><nowiki>UInteger<64></nowiki></code>
| <code>Integer</code>
| <code>UInteger</code>
| {{n/a}}
|-
| [[Python (programming language)|Python]] 2.x
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>int</code>
| {{n/a}}
| <code>long</code>
|-
| [[Python (programming language)|Python]] 3.x
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>int</code>
|-
| [[S-Lang]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| {{n/a}}
|-
| [[Fortran]]
| {{code|INTEGER(KIND {{=}} n)|fortran}}{{ref|Kinds|[f]}}
| {{n/a}}
| {{code|INTEGER(KIND {{=}} n)|fortran}}{{ref|Kinds|[f]}}
| {{n/a}}
| {{code|INTEGER(KIND {{=}} n)|fortran}}{{ref|Kinds|[f]}}
| {{n/a}}
| {{code|INTEGER(KIND {{=}} n)|fortran}}{{ref|Kinds|[f]}}
| {{n/a}}
|
|
|
|-
| [[PHP]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>int</code>{{ref|PHP 32/64 bit long|[m]}}
| {{n/a}}
| <code>int</code>{{ref|PHP 32/64 bit long|[m]}}
| {{n/a}}
| colspan=2 {{n/a}}
| {{ref|PHP bignum|[e]}}
|-
| [[Perl]] 5
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| colspan=2 {{n/a}}{{ref|scalars|[d]}}
| <code>Math::BigInt</code>
|-
| [[Raku (programming language)|Raku]]
| <code>int8</code>
| <code>uint8</code>
| <code>int16</code>
| <code>uint16</code>
| <code>int32</code>
| <code>uint32</code>
| <code>int64</code>
| <code>uint64</code>
| <code>Int</code>
| colspan=2 {{n/a}}
|-
| [[Ruby (programming language)|Ruby]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>Fixnum</code>
| {{n/a}}
| <code>Bignum</code>
|-
| [[Erlang (programming language)|Erlang]]{{ref|Erlang_int|[n]}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>integer()</code>
| {{n/a}}
| <code>integer()</code>{{ref|Erlang_arb|[o]}}
|-
| [[Scala (programming language)|Scala]]
| <code>Byte</code>
| {{n/a}}
| <code>Short</code>
| <code>Char</code>{{ref|Scala Char|[l]}}
| <code>Int</code>
| {{n/a}}
| <code>Long</code>
| {{n/a}}
| {{n/a}}
| {{n/a}}
| <code>scala.math.BigInt</code>
|-
| [[Seed7]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| {{n/a}}
| <code>integer</code>
| {{n/a}}
| {{n/a}}
| {{n/a}}
| <code>bigInteger</code>
|-
| [[Smalltalk]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>SmallInteger</code>{{ref|Smalltalk|[i]}}
| {{n/a}}
| <code>LargeInteger</code>{{ref|Smalltalk|[i]}}
|-
| [[Windows PowerShell]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| {{n/a}}
|-
| [[OCaml]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>int32</code>
| {{n/a}}
| rowspan=2| <code>int64</code>
| {{n/a}}
| <code>int</code> or <code>nativeint</code>
|
| <code>open Big_int;;</code> or <code>big_int</code>
|-
| [[F Sharp (programming language)|F#]]
| <code>sbyte</code>
| <code>byte</code>
| <code>int16</code>
| <code>uint16</code>
| <code>int32</code> or <code>int</code>
| <code>uint32</code>
| <code>uint64</code>
| <code>nativeint</code>
| <code>unativeint</code>
| <code>bigint</code>
|-
| [[Standard ML]]
| {{n/a}}
| <code>Word8.word</code>
| colspan=2 {{n/a}}
| <code>Int32.int</code>
| <code>Word32.word</code>
| <code>Int64.int</code>
| <code>Word64.word</code>
| <code>int</code>
| <code>word</code>
| <code>LargeInt.int</code> or<br/><code>IntInf.int</code>
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| <code>«import Int»</code> or <code>Int8</code>
| <code>«import Word»</code> or <code>Word8</code>
| <code>«import Int»</code> or <code>Int16</code>
| <code>«import Word»</code> or <code>Word16</code>
| <code>«import Int»</code> or <code>Int32</code>
| <code>«import Word»</code> or <code>Word32</code>
| <code>«import Int»</code> or <code>Int64</code>
| <code>«import Word»</code> or <code>Word64</code>
| <code>Int</code>
| <code>«import Word»</code> or <code>Word</code>
| <code>Integer</code>
|-
| [[Eiffel (programming language)|Eiffel]]
| <code>INTEGER_8</code>
| <code>NATURAL_8</code>
| <code>INTEGER_16</code>
| <code>NATURAL_16</code>
| <code>INTEGER_32</code>
| <code>NATURAL_32</code>
| <code>INTEGER_64</code>
| <code>NATURAL_64</code>
| <code>INTEGER</code>
| <code>NATURAL</code>
| {{n/a}}
|-
| [[COBOL]]{{ref|Cobol|[h]}}
| <code>BINARY-CHAR «SIGNED»</code>
| <code>BINARY-CHAR UNSIGNED</code>
| <code>BINARY-SHORT «SIGNED»</code>
| <code>BINARY-SHORT UNSIGNED</code>
| <code>BINARY-LONG «SIGNED»</code>
| <code>BINARY-LONG UNSIGNED</code>
| <code>BINARY-DOUBLE «SIGNED»</code>
| <code>BINARY-DOUBLE UNSIGNED</code>
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Mathematica]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>Integer</code>
|-
| [[Wolfram Language]]
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| colspan=2 {{n/a}}
| <code>Integer</code>
|}
 
* {{note|a68|a}} The ''standard'' constants <code>int shorts</code> and <code>int lengths</code> can be used to determine how many <code>short</code>s and <code>long</code>s can be usefully prefixed to <code>short int</code> and <code>long int</code>. The actual sizes of <code>short int</code>, <code>int</code>, and <code>long int</code> are available as the constants <code>short max int</code>, <code>max int</code>, and <code>long max int</code> etc.
* {{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 <code>short</code>, <code>int</code>, <code>long</code>, and ([[C99]], [[C++11]]) <code>long long</code>, so they are implementation-dependent. In C and C++ <code>short</code>, <code>long</code>, and <code>long long</code> types are required to be at least 16, 32, and 64 bits wide, respectively, but can be more. The <code>int</code> type is required to be at least as wide as <code>short</code> and at most as wide as <code>long</code>, and is typically the width of the word size on the processor of the machine (i.e. on a 32-bit machine it is often 32 bits wide; on 64-bit machines it is sometimes 64 bits wide). [[C99]] and [[C++11]]{{citation needed|date=December 2011}} also define the <code>[u]intN_t</code> exact-width types in the [[stdint.h]] header. See [[C syntax#Integral types]] for more information. In addition the types <code>size_t</code> and <code>ptrdiff_t</code> are defined in relation to the address size to hold unsigned and signed integers sufficiently large to handle array indices and the difference between pointers.
* {{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 <code>n</code> is provided by the <code>SELECTED_INT_KIND</code><ref name="fortranwiki.org">{{cite web|url=http://fortranwiki.org/fortran/show/selected_int_kind|title=selected_int_kind in Fortran Wiki|work=fortranwiki.org|access-date=30 January 2017}}</ref> intrinsic function.
* {{note|a68g|g}} [[ALGOL 68]]G's runtime option <code>--precision "number"</code> can set precision for <code>long long int</code>s to the required "number" significant digits. The ''standard'' constants <code>long long int width</code> and <code>long long max int</code> can be used to determine actual precision.
* {{note|Cobol|h}} [[COBOL]] allows the specification of a required precision and will automatically select an available type capable of representing the specified precision. "<code>PIC S9999</code>", for example, would require a signed variable of four decimal digits precision. If specified as a binary field, this would select a 16-bit signed type on most platforms.
* {{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 ({{code|range 1 .. Integer'Last|ada}}) and Natural ({{code|range 0 .. Integer'Last|ada}}). <code>Short_Short_Integer</code> (8 bits), <code>Short_Integer</code> (16 bits) and <code>Long_Integer</code> (64 bits) are also commonly predefined, but not required by the Ada standard. Runtime checks can be disabled if performance is more important than integrity checks.
* {{note|Ada mod|k}} [[Ada (programming language)|Ada]] modulo types implement modulo arithmetic in all operations, i.e. no range violations are possible. Modulos are not restricted to powers of two.
* {{note|Scala char|l}} Commonly used for characters like Java's char.
* {{note|PHP 32/64 bit long|m}} <code>int</code> in PHP has the same width as <code>long</code> type in C has on that system.{{ref|CInt|[c]}}
* {{note|Erlang int|n}} [[Erlang (programming language)|Erlang]] is dynamically typed. The type identifiers are usually used to specify types of record fields and the argument and return types of functions.<ref>{{cite web|url=http://www.erlang.org/doc/reference_manual/typespec.html|title=Erlang {{--}} Types and Function Specifications|work=erlang.org|access-date=30 January 2017}}</ref>
* {{note|Erlang arb|o}} When it exceeds one word.<ref>{{cite web|url=http://www.erlang.org/doc/efficiency_guide/advanced.html|title=Erlang {{--}} Advanced|work=erlang.org|access-date=30 January 2017}}</ref>
 
=== [[Floating point]] ===
{| class="wikitable sortable"
!
! [[Single precision]]
! [[Double precision]]
! Other precision
! Processor dependent
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>Float</code>
| <code>Long_Float</code>
| {{n/a}}
|-
| [[ALGOL 68]]
| <code>real</code>{{ref|a68|[a]}}
| <code>long real</code>{{ref|a68|[a]}}
| <code>short real</code>, <code>long long real</code>, etc.{{ref|a68g|[d]}}
|-
| [[C (programming language)|C]]
| rowspan=3| <code>float</code>{{ref|lax floats|[b]}}
| rowspan=5| <code>double</code>
| rowspan=3| <code>long double</code>{{ref|C-long-double|[f]}}
|-
| [[C++]] (STL)
|-
| [[Objective-C]] ([[Cocoa (API)|Cocoa]])
| <code>CGFloat</code>
|-
| [[C Sharp (programming language)|C#]]
| rowspan=2| <code>float</code>
| rowspan=3 {{n/a}}
|-
| [[Java (programming language)|Java]]
|-
| [[Go (programming language)|Go]]
| <code>float32</code>
| <code>float64</code>
|-
| [[Rust (programming language)|Rust]]
| <code>f32</code>
| <code>f64</code>
| <code>f16, f128</code>
|-
| [[Swift (programming language)|Swift]]
| <code>Float</code> or <code>Float32</code>
| <code>Double</code> or <code>Float64</code>
| <code>Float80</code>{{ref|Swift-long-double|[g]}}
| <code>CGFloat</code>
|-
| [[D (programming language)|D]]
| <code>float</code>
| <code>double</code>
|
| <code>real</code>
|-
| [[Common Lisp]]
| <code>single-float</code>
| <code>double-float</code>
| <code>float, short-float, long-float</code>
|-
| [[Scheme (programming language)|Scheme]]
|
|
|
|-
| [[ISLISP]]
|
|
|
|-
| [[Pascal (programming language)|Pascal]] ([[Free Pascal|FPC]])
| <code>single</code>
| <code>double</code>
|
| <code>real</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=3| <code>Single</code>
| rowspan=3| <code>Double</code>
| rowspan=3 {{n/a}}
|-
| [[Visual Basic .NET]]
|-
| [[Xojo]]
|-
| [[Python (programming language)|Python]]
| rowspan=2 {{n/a}}
| <code>float</code>
|
|-
| [[JavaScript]]
| <code>Number</code><ref name="Javascript numbers">[https://www.mozilla.org/js/language/E262-3.pdf 8.5 The Number Type]</ref>
| {{n/a}}
|-
| [[S-Lang]]
| <!-- ''x'' = ''value f''; -->
| <!-- ''x'' = ''value''; -->
|
|-
| [[Fortran]]
| colspan=2|<code>REAL(KIND = n)</code>{{ref|real inds|[c]}}
|
|-
| [[PHP]]
|
| <code>float</code>
|
|-
| [[Perl]]
|
|
|
|-
| [[Raku (programming language)|Raku]]
| <code>num32</code>
| <code>num64</code>
|
| <code>Num</code>
|-
| [[Ruby (programming language)|Ruby]]
| {{n/a}}
| <code>Float</code>
| rowspan=4 {{n/a}}
|-
| [[Scala (programming language)|Scala]]
| <code>Float</code>
| <code>Double</code>
|-
| [[Seed7]]
| {{n/a}}
| <code>float</code>
|-
| [[Smalltalk]]
| <code>Float</code>
| <code>Double</code>
|-
| [[Windows PowerShell]]
|
|
|
|-
| [[OCaml]]
| {{n/a}}
| rowspan=2| <code>float</code>
| rowspan=3 {{n/a}}
|-
| [[F Sharp (programming language)|F#]]
| <code>float32</code>
|-
| [[Standard ML]]
| {{n/a}}
|
| <code>real</code>
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| <code>Float</code>
| <code>Double</code>
|
|-
| [[Eiffel (programming language)|Eiffel]]
| <code>REAL_32</code>
| <code>REAL_64</code>
|
|-
| [[COBOL]]
| <code>FLOAT-BINARY-7</code>{{ref|Cobol_ieee|[e]}}
| <code>FLOAT-BINARY-34</code>{{ref|Cobol_ieee|[e]}}
| <code>FLOAT-SHORT</code>, <code>FLOAT-LONG</code>, <code>FLOAT-EXTENDED</code>
|-
| [[Mathematica]]
| {{n/a}}
| {{n/a}}
|
| <code>Real</code>
|}
 
* {{note|a68_real|a}} The ''standard'' constants <code>real shorts</code> and <code>real lengths</code> can be used to determine how many <code>short</code>s and <code>long</code>s can be usefully prefixed to <code>short real</code> and <code>long real</code>. The actual sizes of <code>short real</code>, <code>real</code>, and <code>long real</code> are available as the constants <code>short max real</code>, <code>max real</code> and <code>long max real</code> etc. With the constants <code>short small real</code>, <code>small real</code> and <code>long small real</code> available for each type's [[machine epsilon]].
* {{note|lax floats|b}} declarations of single precision often are not honored
* {{note|real kinds|c}} The value of <code>n</code> is provided by the <code>SELECTED_REAL_KIND</code><ref name="ReferenceA">{{cite web|url=http://fortranwiki.org/fortran/show/selected_real_kind|title=selected_real_kind in Fortran Wiki|work=fortranwiki.org|access-date=30 January 2017}}</ref> intrinsic function.
* {{note|a68g-real|d}} [[ALGOL 68]]G's runtime option <code>--precision "number"</code> can set precision for <code>long long real</code>s to the required "number" significant digits. The ''standard'' constants <code>long long real width</code> and <code>long long max real</code> can be used to determine actual precision.
* {{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 <code>double</code> on many implementations.
* {{note|Swift-long-double|g}} Swift supports 80-bit [[Extended precision#Language support|extended precision]] floating point type, equivalent to <code>long double</code> in C languages.
 
=== [[Complex number]]s ===
{| class="wikitable sortable"
!
! Integer
! Single precision
! Unsigned integer
! Double precision
! Float
! Half and Quadruple precision etc.
! String
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| C
| int x;{{n/a}}
| <code>Complex</code>{{ref|generic type|[b]}}
| unsigned int x;
| <code>Complex</code>{{ref|generic type|[b]}}
| float x; ''or'' double x;
| <code>Complex</code>{{ref|generic type|[b]}}
| char x[]; ''or'' char *x;
|-
| [[ALGOL 68]]
| C++ (STL)
| int x;{{n/a}}
| <code>compl</code>
| unsigned int x;
| <code>long compl</code> etc.
| float x; ''or'' double x;
| <code>short compl</code> etc. and <code>long long compl</code> etc.
| string x;
|-
| [[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>
| Java
| int x;{{n/a}}
| <code>float complex</code>
|
| float x; ''or'' <code>double x;complex</code>
| rowspan=7 {{n/a}}
| String x;
|-
| [[C++]] (STL)
| Pascal
| {{n/a}}<!-- No std::complex<int>. See C++ standard section 26.2 paragraph 2 -->
| var x: integer;
| <code><nowiki>std::complex<float></nowiki></code>
| var x: word;
| <code><nowiki>std::complex<double></nowiki></code>
| var x: real;
| var x: string;
|-
| [[C Sharp (programming language)|C#]]
| Visual Basic
| {{n/a}}
| Dim x as Integer
| {{n/a}}
| <code>System.Numerics.Complex</code><br/>(.NET 4.0)
|-
| [[Java (programming language)|Java]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Go (programming language)|Go]]
| {{n/a}}
| <code>complex64</code>
| <code>complex128</code>
|-
| [[D (programming language)|D]]
| {{n/a}}
| <code>cfloat</code>
| <code>cdouble</code>
|-
| [[Objective-C]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Common Lisp]]
| (complex integer)
| (complex single-float)
| (complex double-float)
| complex
|-
| [[Scheme (programming language)|Scheme]]
|
|
| Dim x as Single ''or'' Dim x as Double
|
| Dim x as String
| rowspan=4 {{n/a}}
|-
| [[Pascal (programming language)|Pascal]]
| {{n/a}}
| {{n/a}}
|
|-
| [[Visual Basic (classic)|Visual Basic]]
| {{n/a}}
| {{n/a}}
|
|-
| [[Visual Basic .NET]]
| {{n/a}}
| {{n/a}}
| <code>System.Numerics.Complex</code><br/>(.NET 4.0)
|-
| [[Perl]]
|
|
| <code>Math::Complex</code>
|
|-
| [[Raku (programming language)|Raku]]
|
| <code>complex64</code>
| <code>complex128</code>
| <code>Complex</code>
|-
| [[Python (programming language)|Python]]
|
|
| <code>complex</code>
| rowspan=15 {{n/a}}
|-
| [[JavaScript]]
| {{n/a}}
| {{n/a}}
|
|-
| [[S-Lang]]
| {{n/a}}
| {{n/a}}
|
|-
| [[Fortran]]
|
| colspan=2|<code>COMPLEX(KIND = n)</code>{{ref|complex kinds|[a]}}
|-
| [[Ruby (programming language)|Ruby]]
| <code>Complex</code>
| {{n/a}}
| <code>Complex</code>
|-
| [[Scala (programming language)|Scala]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Seed7]]
| {{n/a}}
| {{n/a}}
| <code>complex</code>
|-
| [[Smalltalk]]
| <code>Complex</code>
| <code>Complex</code>
| <code>Complex</code>
|-
| [[Windows PowerShell]]
| {{n/a}}
| {{n/a}}
|
|-
| [[OCaml]]
| {{n/a}}
| {{n/a}}
| <code>Complex.t</code>
|-
| [[F Sharp (programming language)|F#]]
|
|
| <code>System.Numerics.Complex</code><br/>(.NET 4.0)
|-
| [[Standard ML]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| {{n/a}}
| <code>Complex{{Not a typo|.}}Complex Float</code>
| <code>Complex{{Not a typo|.}}Complex Double</code>
|-
| [[Eiffel (programming language)|Eiffel]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[COBOL]]
| Python
| {{n/a}}
| x = ''value''
| {{n/a}}
| x = ''value''
| {{n/a}}
| x = ''value''
| x = "''string''"
|-
| [[Mathematica]]
| [[S-Lang_(programming_language)|S-Lang]]
| <code>Complex</code>
| x = ''value''
| {{n/a}}
| x = ''value''
| {{n/a}}
| x = ''value''
| <code>Complex</code>
| x = "''string''"
|}
 
* {{note|complex kinds|a}} The value of <code>n</code> is provided by the <code>SELECTED_REAL_KIND</code><ref name="ReferenceA" /> intrinsic function.
== Logical cycles ==
* {{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 data type|Boolean]]
! rowspan=2| [[Enumerated type|Enumeration]]
! rowspan=2| [[Object (computer science)|Object]]/[[Top type|Universal]]
|-
! [[Character (computing)|Character]]
! [[String (computer science)|String]]{{ref|string|[a]}}
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>Character</code>
| <code>String</code>, <code>Bounded_String</code>, <code>Unbounded_String</code>
| <code>Boolean</code>
| <code>(''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'')</code>
| <code>tagged null record</code>
|-
| [[ALGOL 68]]
| <code>char</code>
| <code>string</code>, <code>bytes</code>
| <code>bool</code>, <code>bits</code>
| {{N/A|N/A}} - [http://rosettacode.org/wiki/Enumerations#ALGOL_68 User defined]
| {{N/A|N/A}}
|-
| [[C (programming language)|C]] ([[C99]])
| rowspan=2| <code>char</code>, <code>wchar_t</code>
| {{N/A|N/A}}
| rowspan=2| <code>bool</code>{{ref|int bool|[b]}}
| 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|<code>«std::»string</code>]]
|-
| [[Objective-C]]
| <code>unichar</code>
| <code>NSString *</code>
| <code>BOOL</code>
| <code>id</code>
|-
| [[C Sharp (programming language)|C#]]
| rowspan=2| <code>char</code>
| <code>string</code>
| <code>bool</code>
| <code>enum ''name'' { ''item<sub>1</sub>''« = ''value''», ''item<sub>2</sub>''« = ''value''», ''...'' }</code>
| object
|-
| [[Java (programming language)|Java]]
| <code>String</code>
| <code>boolean</code>
| <code>enum ''name'' { ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }</code>
| <code>Object</code>
|-
| [[Go (programming language)|Go]]
| <code>byte</code>, <code>rune</code>
| <code>string</code>
| <code>bool</code>
| <code>const (<br/>{{Spaces|3}}''item{{sub|1}}'' = ''iota''<br/>{{Spaces|3}}''item{{sub|2}}''<br/>{{Spaces|3}}''...''<br/>)</code>
| <code>interface{}</code>
|-
| [[Rust (programming language)|Rust]]
| <code>char</code>
| <code>String</code>
| <code>bool</code>
| <code>enum ''name'' { ''item{{sub|1}}''« = ''value''», ''item{{sub|2}}''« = ''value''», ''...'' }</code>
| <code>std::any::Any</code>
|-
| [[Swift (programming language)|Swift]]
| <code>Character</code>
| <code>String</code>
| <code>Bool</code>
| <code>enum ''name'' { case ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }</code>
| <code>Any</code>
|-
| [[D (programming language)|D]]
| <code>char</code>
| <code>string</code>
| <code>bool</code>
| <code>enum ''name'' { ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }</code>
| <code>std.variant.Variant</code>
|-
| [[Common Lisp]]
| <code>character</code>
| <code>string</code>
| <code>boolean</code>
| <code>(member ''item<sub>1</sub>'' ''item<sub>2</sub>'' ''...'')</code>
| <code>t</code>
|-
| [[Scheme (programming language)|Scheme]]
|
|
|
|
|
|-
| [[ISLISP]]
|
|
|
|
|
|-
| Pascal (ISO)
| rowspan=2| <code>char</code>
| {{N/A|N/A}}
| rowspan=2| <code>boolean</code>
| rowspan=2| <code>( ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' )</code>
| {{N/A|N/A}}
|-
| [[Object Pascal]] ([[Delphi (software)|Delphi]])
| <code>string</code>
| <code>variant</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| {{N/A|N/A}}
| rowspan=3| <code>String</code>
| rowspan=3| <code>Boolean</code>
| rowspan=3| <code>Enum ''name''<br/>{{Spaces|3}}''item{{sub|1}}'' «= ''value''»<br/>{{Spaces|3}}''item{{sub|2}}'' «= ''value»<br/>{{Spaces|3}}...''<br/>End Enum</code>
| [[Variant type|{{code|Variant}}]]
|-
| [[Visual Basic .NET]]
| <code>Char</code>
| <code>Object</code>
|-
| [[Xojo]]
| {{N/A|N/A}}
| <code>Object</code> or <code>Variant</code>
|-
| [[Python (programming language)|Python]]
| {{N/A|N/A}}{{ref|string as char|[d]}}
| <code>str</code>
| <code>bool</code>
| {{pre|1=
{{codett|2=python|import enum}}
 
{{codett|2=python|class Name(enum.Enum):}}
{| class="wikitable"
''item{{sub|1}}'' = ''value''
''item{{sub|2}}'' = ''value''
''...''
}}
| <code>object</code>
|-
| [[JavaScript]]
!
| {{N/A|N/A}}{{ref|string as char|[d]}}
| <code>String</code>
| <code>Boolean</code>
|
| <code>Object</code>
|-
| [[S-Lang]]
|
|
|
|
|
|-
| [[Fortran]]
| {{code|2=fortran|1=CHARACTER(LEN = *)}}
| {{code|2=fortran|1=CHARACTER(LEN = :), allocatable}}
| {{code|2=fortran|1=LOGICAL(KIND = n)}}{{ref|logical kinds|[f]}}
|
| <code>CLASS(*)</code>
|-
| [[PHP]]
| {{N/A|N/A}}{{ref|string as char|[d]}}
| <code>string</code>
| <code>bool</code>
|
| (type declaration omitted)
|-
| [[Perl]]
| {{N/A|N/A}}{{ref|string as char|[d]}}
|
|
|
| <code>UNIVERSAL</code>
|-
| [[Raku (programming language)|Raku]]
| <code>Char</code>
| <code>Str</code>
| <code>Bool</code>
| <code>enum ''name<item<sub>1</sub> item<sub>2</sub> ...>''</code><br/><code>enum ''name <<:item<sub>1</sub>(value) :item<sub>2</sub>(value) ..>>''</code>
| <code>Mu</code>
|-
| [[Ruby (programming language)|Ruby]]
| {{N/A|N/A}}{{ref|string as char|[d]}}
| <code>String</code>
| <code>Object</code>{{ref|Ruby's bool|[c]}}
|
| <code>Object</code>
|-
| [[Scala (programming language)|Scala]]
| <code>Char</code>
| <code>String</code>
| <code>Boolean</code>
| <code>object ''name'' extends Enumeration {<br/>{{Spaces|3}}''val item{{sub|1}}, item{{sub|2}}, ... = Value''<br/>}</code>
| <code>Any</code>
|-
| [[Seed7]]
| <code>char</code>
| <code>string</code>
| <code>boolean</code>
| <code>const type'': name'' is new enum<br/>{{Spaces|3}}''item{{sub|1}},''<br/>{{Spaces|3}}''item{{sub|2}},''<br/>{{Spaces|3}}''...''<br/>end enum;</code>
|
|-
| [[Windows PowerShell]]
|
|
|
|
|
|-
| [[OCaml]]
| rowspan=3| <code>char</code>
| rowspan=3| <code>string</code>
| rowspan=3| <code>bool</code>
| {{N/A|N/A}}{{ref|enum|[e]}}
| {{N/A|N/A}}
|-
| [[F Sharp (programming language)|F#]]
| <code>type ''name'' = ''item<sub>1</sub>'' = ''value'' {{pipe}}''item<sub>2</sub>'' = ''value'' {{pipe}} ''...''</code>
| <code>obj</code>
|-
| [[Standard ML]]
| {{N/A|N/A}}{{ref|enum|[e]}}
| {{N/A|N/A}}
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| <code>Char</code>
| <code>String</code>
| <code>Bool</code>
| {{N/A|N/A}}{{ref|enum|[e]}}
| {{N/A|N/A}}
|-
| [[Eiffel (programming language)|Eiffel]]
| <code>CHARACTER</code>
| <code>STRING</code>
| <code>BOOLEAN</code>
| {{N/A|N/A}}
| <code>ANY</code>
|-
| [[COBOL]]
| <code>PIC X</code>
| <code>''PIC X(''string length'')''</code> or <code>PIC&nbsp;X«X...»</code>
| <code>''PIC 1«(''number of digits'')»''</code> or <code>PIC&nbsp;1«1...»</code>
| {{N/A|N/A}}
| <code>OBJECT REFERENCE</code>
|-
| [[Mathematica]]
| {{N/A|N/A}}{{ref|string as char|[d]}}
| <code>String</code>
|
|
| {{N/A|N/A}}
|}
 
* {{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 ''<code>TrueClass</code>'' evaluates to true and everything in ''<code>FalseClass</code>'' evaluates to false.
* {{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 ''<code>n</code>'' is provided by the <code>SELECTED_INT_KIND</code><ref name="fortranwiki.org" /> intrinsic function.
 
== Derived types ==
=== [[Array data type|Array]] ===
{{Further|Comparison of programming languages (array)}}
{| class="wikitable sortable"
|- valign="top"
! rowspan=2|
! colspan=2| fixed size array
! colspan=2| dynamic size array
|- valign="top"
! [[Array data structure#One-dimensional arrays|one-dimensional array]]
! [[Array data structure#Multidimensional arrays|multidimensional array]]
! [[Array data structure#One-dimensional arrays|one-dimensional array]]
! [[Array data structure#Multidimensional arrays|multidimensional array]]
|- valign="top"
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>array (''&lt;first> ''..'' &lt;last>'') of'' &lt;type>''</code><br/>or<br/><code>array (''&lt;discrete_type>'') of'' &lt;type>''</code>
| <code>array (''&lt;first<sub>1</sub>> ''..'' &lt;last<sub>1</sub>>'','' &lt;first<sub>2</sub>> ''..'' &lt;last<sub>2</sub>>'', ''...'') of'' &lt;type>''</code><br/>or<br/><code>array (''&lt;discrete_type<sub>1</sub>>'','' &lt;discrete_type<sub>2</sub>>'','' ...'') of'' &lt;type>''</code>
| <code>array (''&lt;discrete_type> ''range <>) of'' &lt;type>''</code>
| <code>array (''&lt;discrete_type<sub>1</sub>> ''range <>,'' <discrete_type<sub>2</sub>> ''range <>, ''...'') of'' &lt;type>''</code>
|- valign="top"
| [[ALGOL 68]]
| <code>[''first'':''last'']<wbr/>«modename»</code><br/>or simply:<br/><code>[''size'']<wbr/>«modename»</code>
| <code>[''first<sub>1</sub>'':''last<sub>1</sub>'','' first<sub>2</sub>'':''last<sub>2</sub>'']<wbr/>«modename»</code><br/>or<br/><code>[''first<sub>1</sub>'':''last<sub>1</sub>''][''first<sub>2</sub>'':''last<sub>2</sub>'']<wbr/>«modename»</code><br/>etc.
| <code>flex[''first'':''last'']<wbr/>«modename»</code><br/>or simply:<br/><code>flex[''size'']<wbr/>«modename»</code>
| <code>flex[''first<sub>1</sub>'':''last<sub>1</sub>'','' first<sub>2</sub>'':''last<sub>2</sub>'']<wbr/>«modename»</code><br/>or<br/><code>flex[''first<sub>1</sub>'':''last<sub>1</sub>'']<wbr/>flex[''first<sub>2</sub>'':''last<sub>2</sub>'']<wbr/>«modename» ''etc.''</code>
|- 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/>or within a block:<br/><code>''int n = ...; type name''[''n'']</code>
|
|- valign="top"
| [[C++]] (STL)
| colspan=1| <code>[[std::array|«std::»array]]<''type, size''></code>(C++11)
|
| colspan=2| <code>[[std::vector|«std::»vector]]<''type''></code>
|- valign="top"
| [[C Sharp (programming language)|C#]]
| <code>''type''[]</code>
| <code>''type''[{{Not a typo|,,}}''...'']</code>
| <code>System<wbr/>.Collections<wbr/>.ArrayList</code><br/>or<br/><code>System<wbr/>.Collections<wbr/>.Generic<wbr/>.List<wbr/><''type''></code>
|
|- valign="top"
| [[Java (programming language)|Java]]
| <code>''type''[]</code>{{ref|Java's array|[b]}}
| <code>''type''[][]''...''</code>{{ref|Java's array|[b]}}
| <code>ArrayList ''or'' ArrayList<''type''></code>
|
|- valign="top"
| [[D (programming language)|D]]
| <code>''type''[''size'']</code>
| <code>''type''[''size<sub>1</sub>''][''size<sub>2</sub>'']</code>
| <code>''type''[]</code>
|
|- valign="top"
| [[Go (programming language)|Go]]
| <code>[''size'']''type''</code>
| <code>[''size<sub>1</sub>''][''size<sub>2</sub>'']''...type''</code>
| <code>[]type</code>
| <code>[][]type</code>
|- valign="top"
| [[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>
|- valign="top"
| [[Swift (programming language)|Swift]]
|
|
| <code>[''type'']</code> or <code>Array<''type''></code>
| <code><nowiki>[[</nowiki>''type''<nowiki>]]</nowiki></code> or <code>Array<Array<''type''>></code>
|- valign="top"
| [[Objective-C]]
| <code>NSArray</code>
|
| <code>NSMutableArray</code>
|
|- valign="top"
| [[JavaScript]]
| {{n/a}}
| {{n/a}}
| colspan=2|<code>Array</code>{{ref|JavaScript's array|[d]}}
|- valign="top"
| [[Common Lisp]]
| {{code|2=lisp|(simple-array type (dimension))}}
| {{code|2=lisp|(simple-array type (dimension1 dimension2))}}
| {{code|2=lisp|(array type (dimension))}}
| {{code|2=lisp|(array type (dimension1 dimension2))}}
|- valign="top"
| [[Scheme (programming language)|Scheme]]
|
|
|
|
|- valign="top"
| [[ISLISP]]
|
|
|
|
|- valign="top"
| [[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/>or<br/><code> array[''first<sub>1</sub>''..''last<sub>1</sub>'','' first<sub>2</sub>''..''last<sub>2</sub>'','' ...''] of ''type''</code>{{ref|subrange|[c]}}
| {{n/a}}
| {{n/a}}
|- valign="top"
| [[Object Pascal]] ([[Delphi (software)|Delphi]])
| <code>array of'' type''</code>
| <code>array of array ''...'' of ''type''</code>
|- valign="top"
| [[Visual Basic (classic)|Visual Basic]]
| <code>Dim x(''last'') As ''type''</code>
| <code>Dim x(''last<sub>1</sub>'', ''last<sub>2</sub>'',''...'') As ''type''</code>
|
|
|- valign="top"
| [[Visual Basic .NET]]
| <code>''type''()</code>
| <code>''type''({{Not a typo|,,}}''...'')</code>
| <code>System<wbr/>.Collections<wbr/>.ArrayList</code><br/>or<br/><code>System<wbr/>.Collections<wbr/>.Generic<wbr/>.List<wbr/>(Of ''type'')</code>
|
|- valign="top"
| [[Python (programming language)|Python]]
|
|
| <code>list</code>
|
|- valign="top"
| [[S-Lang]]
| <code>x = ''type''[''size''];</code>
| <code>x = ''type''[''size<sub>1</sub>'','' size<sub>2</sub>'', ''...''];</code>
|
|
|- valign="top"
| [[Fortran]]
| <code>''type'' :: ''name''(''size'')</code>
| <code>''type'' :: ''name''(''size''<sub>1</sub>, ''size<sub>2</sub>'',...)</code>
| <code>''type'', ALLOCATABLE :: ''name''(:)</code>
| <code>''type'', ALLOCATABLE :: ''name''(:,:,...)</code>
|- valign="top"
| [[PHP]]
|
|
| <code>array</code>
|
|- valign="top"
| [[Perl]]
|
|
|
|
|- valign="top"
| [[Raku (programming language)|Raku]]
|
|
| <code>Array[''type''] ''or'' Array of ''type''</code>
|
|- valign="top"
| [[Ruby (programming language)|Ruby]]
|
| <code>x = Array.new(''size<sub>1</sub>''){ Array.new(''size<sub>2</sub>'') }</code>
| <code>Array</code>
|
|- valign="top"
| [[Scala (programming language)|Scala]]
| <code>Array[''type'']</code>
| <code>Array[''...''[Array[''type'']]''...'']</code>
| <code>ArrayBuffer[''type'']</code>
|
|- valign="top"
| [[Seed7]]
| <code>array ''type''</code><br/>or<br/><code>array [''idxType''] ''type''</code>
| <code>array array ''type''</code><br/>or<br/><code>array [''idxType''] array [''idxType''] ''type''</code>
| <code>array ''type''</code><br/>or<br/><code>array [''idxType''] ''type''</code>
| <code>array array ''type''</code><br/>or<br/><code>array [''idxType''] array [''idxType''] ''type''</code>
|- valign="top"
| [[Smalltalk]]
| <code>Array</code>
|
| <code>OrderedCollection</code>
|
|- valign="top"
| [[Windows PowerShell]]
| <code>''type''[]</code>
| <code>''type''[{{Not a typo|,,}}''...'']</code>
|
|
|- valign="top"
| [[OCaml]]
| <code>''type'' array</code>
| <code>''type'' array ''...'' array</code>
|
|
|- valign="top"
| [[F Sharp (programming language)|F#]]
| <code>''type'' []</code><br/>or<br/><code>''type'' array</code>
| <code>''type'' [{{Not a typo|,,}}''...'']</code>
| <code>System<wbr/>.Collections<wbr/>.ArrayList</code><br/>or<br/><code>System<wbr/>.Collections<wbr/>.Generic<wbr/>.List<wbr/><''type''></code>
|
|- valign="top"
| [[Standard ML]]
| <code>''type'' vector ''or type'' array</code>
|
|
|
|- valign="top"
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| <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>
|
|
|- valign="top"
| [[COBOL]]
| <code>''level-number type'' OCCURS ''size'' «TIMES».</code>
| {{em|one-dimensional array definition...}}
| <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 <code>&</code> operators), values of array types in C are automatically converted to a pointer of its first argument. See [[C syntax#Arrays]] for further details of syntax and pointer operations.
* {{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 <code>DEPENDING ON</code> clause in COBOL does not create a ''true'' variable length array and will always allocate the maximum size of the array.
 
=== Other types ===
{| class="wikitable sortable"
! rowspan=2|
! colspan=2|Simple composite types
! rowspan=2|[[Algebraic data type]]s
! rowspan=2|[[Union (computer science)|Union]]s
|-
! [[Record (computer science)|Record]]s
! [[Tuple]] expression
|-
| [[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/>end record ''{{pipe}}'' null record'']''</code>
| {{N/A|N/A}}
| {{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/>end record</code>
|-
| [[ALGOL 68]]
| <code>struct ''(''modename ''«fieldname»,'' ...'');''</code>
| colspan=2 align=center| Required types and operators can be [[User-defined function|user-defined]]
| <code>union ''(''modename'','' ...'');''</code>
|-
| [[C (programming language)|C]] ([[C99]])
| rowspan=2| <code>struct ''«name»'' {''type name'';''...''};</code>
| rowspan=2 {{N/A|N/A}}
| rowspan=3 {{N/A|N/A}}
| rowspan=3| <code>union {''type name'';''...''};</code>
|-
| [[Objective-C]]
|-
| [[C++]]
| <code>struct ''«name»'' {''type name'';''...''};</code>{{ref|C++'s struct|[b]}}
| <code>[[C++11#Tuple types|«std::»tuple]]<''type{{sub|1}}..type{{sub|n}}''></code>
|-
| [[C Sharp (programming language)|C#]]
| <code>struct ''name'' {''type name'';''...''}</code>
| <code>(''val{{sub|1}}'', ''val{{sub|2}}'', ''...'' )</code>
|
| rowspan=3 {{N/A|N/A}}
|-
| [[Java (programming language)|Java]]
| {{N/A|N/A}}{{ref|just classes|[a]}}
|
|
|-
| [[JavaScript]]
|
| {{N/A|N/A}}
|
|-
| [[D (programming language)|D]]
| <code>struct ''name'' {''type name'';''...''}</code>
|
| <code>std.variant.Algebraic''!(type,...)''</code>
| <code>union {''type name'';''...''}</code>
|-
| [[Go (programming language)|Go]]
| <code>struct { {{indent|2}}''«name» type''{{indent|2}}''...''<br/>}</code>
|
|
|
|-
| [[Rust (programming language)|Rust]]
| <code>struct name {''name:'' type'', ...''}</code>
| <code>(''val{{sub|1}}'','' val{{sub|2}}'', ''...'' )</code>
| <code>enum name { ''Foo''(''types'')'', ...''}</code>
| <code>union name {''name:'' type'', ...''}</code>
|-
| [[Swift (programming language)|Swift]]
| <code>struct ''name'' {''{{indent|2}}''var'' name «'':'' type»{{indent|2}}...<br/>''}</code>
| <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>
|
|-
| [[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]}}
|
|
|-
| [[Scheme (programming language)|Scheme]]
| {{N/A|N/A}}
|
|
|-
| [[ISLISP]]
|
|
|
|-
| [[Pascal (programming language)|Pascal]]
| <code>record{{indent|2}}''name'': ''type'';{{indent|2}}''...<br/>''end</code>
| {{N/A|N/A}}
| {{N/A|N/A}}
| <code>record{{indent|2}}case ''type'' of{{indent|2}}''value'': (''types'');{{indent|2}}''...''<br/>end</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
|
|
|
|
|-
| [[Visual Basic .NET]]
| <code>Structure ''name''{{indent|2}}Dim ''name'' As ''type''{{indent|2}}''...''<br/>End Structure</code>
| <code>(''val{{sub|1}}'', ''val{{sub|2}}'', ''...'' )</code>
|
|
|-
| [[Python (programming language)|Python]]
| {{N/A|N/A}}{{ref|just classes|[a]}}
| <code>«(''»val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'' «)»</code>
|
| {{N/A|N/A}}
|-
| [[S-Lang]]
| <code>struct {''name [=value], ...''}</code>
|
|
|
|-
| [[Fortran]]
| <code>TYPE ''name{{indent|2}}type'' :: ''name{{indent|2}}...<br/>''END TYPE</code>
|
|
|
|-
| [[PHP]]
| {{N/A|N/A}}{{ref|just classes|[a]}}
|
|
|
|-
| [[Perl]]
| {{N/A|N/A}}{{ref|Perl's records|[d]}}
|
|
| rowspan=3 {{N/A|N/A}}
|-
| [[Raku (programming language)|Raku]]
| {{N/A|N/A}}{{ref|just classes|[a]}}
|
|
|-
| [[Ruby (programming language)|Ruby]]
| {{code|lang=ruby|1=OpenStruct.new({:name => value})}}
|
|
|-
| [[Scala (programming language)|Scala]]
| <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/>or<br/><code>abstract class ''name''{{indent|2}}case object ''Foo'' extends ''name''{{indent|2}}case object ''Bar'' extends ''name''{{indent|2}}''...''</code><br/>or a combination of case classes and case objects
|
|-
| [[Windows PowerShell]]
|
|
|
|
|-
| [[OCaml]]
| rowspan=2| <code>type ''name'' = {«''mutable''» ''name'' : ''type'';''...''}</code>
| 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 {{N/A|N/A}}
|-
| [[F Sharp (programming language)|F#]]
|-
| [[Standard ML]]
| <code>type ''name'' = {''name'' : ''type'',''...''}</code>
| rowspan=2| <code>(''val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'' )</code>
| <code>datatype ''name'' = ''Foo'' «of ''type''» {{pipe}} ''Bar'' «of ''type''» {{pipe}} ''...''</code>
|-
| [[Haskell]]
| <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>
| {{N/A|N/A}}
| {{N/A|N/A}}
| <code>''name'' REDEFINES ''variable type''.</code>
|}
 
* {{note|just classes|a}} Only classes are supported.
* {{note|C++'s struct|b}} <code>struct</code>s in C++ are actually classes, but have default public visibility and ''are'' also [[Plain old data structure|POD]] objects. C++11 extended this further, to make classes act identically to POD objects in many more cases.
* {{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.
* {{note|enum|e}} Enumerations in this language are algebraic types with only nullary constructors
 
== Variable and constant declarations ==
{| class="wikitable sortable"
!
! variable
! constant
! type synonym
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>''identifier'' : ''type«'' := ''initial_value»''</code>{{ref|Ada declaration|[e]}}
| <code>''identifier'' : constant ''type'' := ''final_value''</code>
| <code>subtype ''identifier'' is ''type''</code>
|-
| [[ALGOL 68]]
| <code>modename name« := ''initial_value''»;</code>
| <code>modename name = ''value'';</code>
| <code>[[typedef|mode]] synonym = modename;</code>
|-
| [[C (programming language)|C]] ([[C99]])
| rowspan=3| <code>''type name''« = ''initial_value''»;</code>
| rowspan=2| <code>enum{ ''name'' = ''value'' };</code>
| rowspan=3| <code>[[typedef]] ''type synonym'';</code>
|-
| [[Objective-C]]
|-
| [[C++]]
| <code>const ''type name'' = ''value'';</code>
|-
| [[C Sharp (programming language)|C#]]
| <code>''type name<sub>1</sub>''« = ''initial_value''», ''name<sub>2</sub>''« = ''initial_value''», ''...'';</code><br/>or<br/><code>var ''name'' = ''initial_value'';</code>
| <code>const ''type name'' = ''value'', ''name'' = ''value'', ''...'';</code><br/>or<br/><code>readonly ''type name'' = ''value'', ''name'' = ''value'', ''...'' ;</code>
| <code>using ''synonym'' = ''type'';</code>
|-
| [[D (programming language)|D]]
| <code>''type name''« = ''initial_value''»;</code><br/>or<br/><code>auto ''name'' = ''value'';</code>
| <code>const ''type name'' = ''value'';</code><br/>or<br/><code>immutable ''type name'' = ''value'';</code>
| <code>alias ''type synonym'';</code>
|-
| [[Java (programming language)|Java]]
| <code>''type name''« = ''initial_value''»;</code>
| <code>final ''type name'' = ''value'';</code>
| rowspan=2 {{n/a}}
|-
| [[JavaScript]]
| <code>var ''name''« = ''initial_value''»;</code> or<br/><code>let ''name''« = ''initial_value''»;</code> (since [[ECMAScript]] 2015)
| <code>const ''name'' = ''value'';</code> (since [[ECMAScript]] 2015)
|-
| [[Go (programming language)|Go]]
| <code>var ''name type''« = ''initial_value''»</code><br/>or<br/><code>''name'' := ''initial_value''</code>
| <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>static mut ''NAME'': ''type'' = ''value'';</code>
| <code>let ''name''«: ''type''»« = ''initial_value''»;</code><br/><code>const ''NAME'': ''type'' = ''value'';</code><br/><br/><code>static ''NAME'': ''type'' = ''value'';</code>
| <code>type ''synonym'' = ''typename'';</code>
|-
| [[Swift (programming language)|Swift]]
| <code>var ''name'' «: ''type''»« = ''initial_value''»</code>
| <code>let ''name'' «: ''type''» = ''value''</code>
| <code>typealias ''synonym'' = ''type''</code>
|-
| [[Common Lisp]]
| <code>(defparameter ''name initial-value'')</code><br/>or<br/><code>(defvar ''name initial-value'')</code>
| <code>(defconstant ''name value'')</code>
| <code>(deftype ''synonym'' () <nowiki>'</nowiki>''type'')</code>
|-
| [[Scheme (programming language)|Scheme]]
| <code>(define ''name initial_value'')</code>
|
|
|-
| [[ISLISP]]
| <code>(defglobal ''name initial_value'')</code><br/>or<br/><code>(defdynamic ''name initial_value'')</code>
| <code>(defconstant ''name value'')</code>
| {{n/a}}
|-
| [[Pascal (programming language)|Pascal]]{{ref|Pascal's declarations|[a]}}
| <code>''name'': ''type''« = ''initial_value''»</code>
| <code>''name'' = ''value''</code>
| <code>''synonym'' = ''type''</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| <code>Dim ''name'' «As ''type''»</code>
| rowspan=3| See notes to left.
Constants use the same syntax, and:
* use <code>Const</code> instead of <code>Dim</code>
* have a restriction to only certain primitive types<br/><code>Const ''name<sub>1</sub>'' «As ''type''» = ''value'', ''name<sub>2</sub>'' «As ''type»'' = ''value, ...''</code>
|
|-
| [[Visual Basic .NET]]<ref>{{Cite web|url=https://ljw1004.github.io/vbspec/vb.html|title=Grammar vb|date=2016-06-17|website=Visual Basic Language Specification|archive-url=https://web.archive.org/web/20190829225051/https://ljw1004.github.io/vbspec/vb.html|archive-date=2019-08-29|url-status=live|access-date=2019-08-29}}</ref>
| The variable declaration syntax of VB.NET is unusually difficult to precisely describe.
Given that there exist the identifier suffixes ("modifiers"):
* <code>type_character</code>, available as an alternative to an <code>As</code> clause for some primitive data types;
* <code>nullable_specifier</code>; and
* <code>array_specifier</code>;
and that
* a <code>modified_identifier</code> is of the form <code>identifier«type_character»«nullable_specifier»«array_specifier»</code>;
* a <code>modified_identifier_list</code> is a comma-separated list of two or more occurrences of <code>modified_identifier</code>; and
* a <code>declarator_list</code> is a comma-separated list of declarators, which can be of the form
** <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
** <code>''modified_identifier_list'' «As ''«non_array_type''««''array_rank_specifier''»»</code> ''(multiple declarator);''
valid declaration statements are of the form
{{In5}}<code>Dim ''declarator_list''</code>,
where, for the purpose of semantic analysis, to convert the <code>declarator_list</code> to a list of only single declarators:
* The <code>As</code> clauses of each ''multiple declarator'' is distributed over its <code>modified_identifier_list</code>
* 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 <code>identifier</code>,
* a <code>type_character</code> and <code>As</code> clause do not both appear;
* if an <code>As</code> clause is present,
** an <code>array_rank_specifier</code> does not appear both as a modification of the identifier and on the type of the <code>As</code> clause;
* an <code>unmodified_type</code> can be determined, by the rule that,
** if a <code>type_character</code> or <code>As</code> clause is present,
*** <code>unmodified_type</code> is that specified by such construct,
** and that otherwise,
*** either <code>Option Infer</code> must be on and the <code>identifier</code> must have an initializer, in which case <code>unmodified_type</code> is that of the initializer, or
*** <code>Option Strict</code> must be off, in which case <code>unmodified_type</code> is <code>Object</code>;
* its <code>final_type</code> is its <code>unmodified_type</code> prepended before its modifiers;
* its <code>final_type</code> is a valid type; and
* if an <code>initial_value</code> is present,
** either <code>Option Strict</code> is on and <code>initial_value</code> has a widening conversion to <code>final_type</code>, or
** <code>Option Strict</code> is off and <code>initial_value</code> has a narrowing conversion to <code>final_type</code>.
If <code>Option Explicit</code> is off, variables do not require explicit declaration; they are declared implicitly when used:
<syntaxhighlight lang="basic" inline>name = initial_value</syntaxhighlight>
| <code>Imports ''synonym'' = ''type''</code>
|-
| [[Xojo]]
| <code>Dim ''name'' «As ''type''»« = ''initial_value»''</code>
| {{n/a}}
|-
| [[Python (programming language)|Python]]
| <code>''name«: type»'' = ''initial_value''</code>
| rowspan=2 {{n/a}}
| <code>''synonym'' = ''type''</code>{{ref|variable types|[b]}}
|-
| [[CoffeeScript]]
| <code>''name'' = ''initial_value''</code>| <code>''name'' = ''initial_value''</code>
|-
| [[S-Lang]]
| <code>''name'' = ''initial_value'';</code>
|
| <code>typedef struct {...} ''typename''</code>
|-
| [[Fortran]]
| <code>''type'' :: ''name''</code>
| <code>''type'', PARAMETER :: ''name'' = ''value''</code>
|
|-
| [[PHP]]
| <code>$''name'' = ''initial_value'';</code>
| <code>define("''name''", ''value'');<br/>const ''name'' = ''value (5.3+)''</code>
| rowspan=2 {{n/a}}
|-
| [[Perl]]
| <code>«my» $''name''« = ''initial_value''»;</code>{{ref|Perl's my keyword|[c]}}
| <code>use constant ''name'' => ''value'';</code>
|-
| [[Raku (programming language)|Raku]]
| <code>«my «''type''»» ''$name«'' = ''initial_value''»;</code>{{ref|Perl's my keyword|[c]}}
| <code>«my «''type''»» constant ''name'' = ''value'';</code>
| <code>::''synonym'' ::= ''type''</code>
|-
| [[Ruby (programming language)|Ruby]]
| <code>''name'' = ''initial_value''</code>
| <code>''Name'' = ''value''</code>
| <code>''synonym'' = ''type''</code>{{ref|variable types|[b]}}
|-
| [[Scala (programming language)|Scala]]
| <code>var ''name''«: ''type''» = ''initial_value''</code>
| <code>val ''name''«: ''type''» = ''value''</code>
| <code>type ''synonym'' = ''type''</code>
|-
| [[Windows PowerShell]]
| <code>«[''type'']» $''name'' = ''initial_value''</code>
| {{n/a}}
| {{n/a}}
|-
| [[Bash shell]]
| <code>name=''initial_value''</code>
| {{n/a}}
| {{n/a}}
|-
| [[OCaml]]
| <code>let ''name''« : ''type'' ref» = ref ''value''</code>{{ref|ML ref|[d]}}
| rowspan=2| <code>let ''name'' «: ''type''» = ''value''</code>
| rowspan=3| <code>type ''synonym'' = ''type''</code>
|-
| [[F Sharp (programming language)|F#]]
| <code>let mutable ''name'' «: ''type''» = ''value''</code>
|-
| [[Standard ML]]
| <code>val ''name'' «: ''type'' ref» = ref ''value''</code>{{ref|ML ref|[d]}}
| <code>val ''name'' «: ''type''» = ''value''</code>
|-
| [[Haskell]]
|
| <code>«''name''::''type'';» ''name'' = ''value''</code>
| <code>type ''Synonym'' = ''type''</code>
|-
| [[Forth (programming language)|Forth]]
| <code>VARIABLE ''name''</code> (in some systems use <code>''value'' VARIABLE ''name''</code> instead)
| <code>''value'' CONSTANT ''name''</code>
|
|-
| [[COBOL]]
| <code>''level-number name type clauses''.</code>
| <code>«0»1 ''name'' CONSTANT «AS» ''value''.</code>
| <code>''level-number name type clauses'' «IS» TYPEDEF.</code>
|-
| [[Mathematica]]
| <code>name=''initial_value''</code>
| {{n/a}}
| {{n/a}}
|}
 
* {{note|Pascal's declarations|a}} Pascal has declaration blocks. See [[#Functions|functions]].
* {{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 <code>!</code> and <syntaxhighlight lang="sml" inline>:=</syntaxhighlight> operators, respectively.
* {{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 <code>let</code> or <code>let mut</code> variable and it is never assigned to later, there is an [https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#unused-variables "unused variable" warning]. If no value is provided for a <code>const</code> or <code>static</code> or <code>static mut</code> variable, there is an error. There is a [https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html?#non-upper-case-globals "non-upper-case globals"] error for non-uppercase <code>const</code> variables. After it is defined, a <code>static mut</code> variable can only be assigned to in an <code>unsafe</code> block or function.
 
== [[Control flow]] ==
=== [[Conditional (programming)|Conditional]] statements ===
{| class="wikitable sortable"
|- valign="top"
!
! if
! else if
! [[while loop|while]]
! [[do while loop|do while]]
! [[for loop|for i = 1 to N]]
! [[switch statement|select case]]
! [[Conditional (programming)#If expressions|conditional expression]]
|- valign="top"
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>if ''condition'' then{{indent|2}}''statements''<br/>«else{{indent|2}}''statements''»<br/>end if</code>
| <code>if ''condition{{sub|1}}'' then{{indent|2}}''statements''<br/>elsif ''condition{{sub|2}}'' then{{indent|2}}''statements''<br/>''...''<br/>«else{{indent|2}}''statements''»<br/>end if</code>
| <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/>end case</code>
| <code>(if ''condition{{sub|1}}'' then{{indent|2}}''expression{{sub|1}}''<br/>«elsif ''condition{{sub|2}}'' then{{indent|2}}''expression{{sub|2}}''»<br/>''...''<br/>else{{indent|2}}''expression{{sub|n}}''<br/>)</code><br/>or<br/><code>(case ''expression'' is{{indent|2}}when ''value_list{{sub|1}}'' => ''expression{{sub|1}}''{{indent|2}}when ''value_list{{sub|2}}'' => ''expression{{sub|2}}''{{indent|2}}''...''{{indent|2}}«when others => ''expression{{sub|n}}''»<br/>)</code>
|- valign="top"
| [[Seed7]]
| <code>if ''condition'' then{{indent|2}}''statements''<br/>«else{{indent|2}}''statements''»<br/>end if</code>
| <code>if ''condition{{sub|1}}'' then{{indent|2}}''statements''<br/>elsif ''condition{{sub|2}}'' then{{indent|2}}''statements''<br/>''...''<br/>«else{{indent|2}}''statements''»<br/>end if</code>
| <code>case ''expression'' of{{indent|2}}when ''set1'' : ''statements''{{indent|2}}''...''{{indent|2}}«otherwise: ''statements''»<br/>end case</code>
|
|- valign="top"
| [[Modula-2]]
| <code>if ''condition'' then{{indent|2}}''statements''<br/>«else{{indent|2}}''statements''»<br/>end</code>
| <code>if ''condition{{sub|1}}'' then{{indent|2}}''statements''<br/>elsif ''condition{{sub|2}}'' then{{indent|2}}''statements''<br/>''...''<br/>«else{{indent|2}}''statements''»<br/>end</code>
| rowspan=1 | <code>case ''expression'' of{{indent|2}}''caseLabelList'' : ''statements'' {{pipe}}{{indent|2}}''...''{{indent|2}}«else ''statements''»<br/>end</code>
|
|- valign="top"
| [[ALGOL 68]]
| <code>if ''condition'' then ''statements'' «else ''statements''» fi</code>
| <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/>(brief form)
| <syntaxhighlight lang="text" inline>( condition | statements «| statements» )</syntaxhighlight>
| <syntaxhighlight lang="text" inline>( condition | statements |: condition | statements )</syntaxhighlight>
| <syntaxhighlight lang="text" inline>( variable | statements,... «| statements» )</syntaxhighlight>
|
|- valign="top"
| [[APL (programming language)|APL]]
| <code>:If ''condition''{{indent|2}}''instructions''<br/>«:Else{{indent|2}}''instructions''»<br/>:EndIf</code>
| <code>:If ''condition''{{indent|2}}''instructions''<br/>:ElseIf ''condition''{{indent|2}}''instructions''<br/>''...''<br/>«:Else{{indent|2}}''instructions''»<br/>:EndIf</code>
| <code>:Select ''expression''{{indent|2}}:Case ''case1''{{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}«:Else{{indent|4}}''instructions''»<br/>:EndSelect</code>
| <code>{''condition'':''valueIfTrue'' ⋄ ''valueIfFalse''}</code>
|- valign="top"
| [[C (programming language)|C]] ([[C99]])
| rowspan=7| <code>if (''condition'') ''instructions''<br/>«else ''instructions''»</code><br/><code>instructions</code> can be a single statement or a block in the form of: <code>{ ''statements'' }</code>
| rowspan=7| <code>if (''condition'') ''instructions''<br/>else if (''condition'') ''instructions''<br/>''...''<br/>«else ''instructions»''</code><br/>or<br/><code>if (''condition'') ''instructions''<br/>else { if (''condition'') ''instructions'' }</code>
| rowspan=7| <code>switch (''variable'') { {{indent|2}}case ''case1'': ''instructions'' «; break;»{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br/>}</code>
| rowspan=7| <code>''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''</code>
|- valign="top"
| [[Objective-C]]
|- valign="top"
| [[C++]] (STL)
|- valign="top"
| [[D (programming language)|D]]
|- valign="top"
| [[Java (programming language)|Java]]
|- valign="top"
| [[JavaScript]]
|- valign="top"
| [[PHP]]
|- valign="top"
| [[C Sharp (programming language)|C#]]
| <code>if (''condition'') ''instructions''<br/>«else ''instructions''»</code>
<code>instructions</code> can be a single statement or a block in the form of: <code>{ ''statements'' }</code>
| <code>if (''condition'') ''instructions''<br/>else if (''condition'') ''instructions''<br/>''...''<br/>«else ''instructions''»</code>
| <code>switch (''variable'')<br/>{ {{indent|2}}case ''case{{sub|1}}'':{{indent|4}}''instructions''{{indent|4}}«''break_or_jump_statement''»{{indent|2}}''...''{{indent|2}}«default:{{indent|4}}''instructions''{{indent|4}}''break_or_jump_statement''»<br/>}</code>
All non-empty cases must end with a <code>break</code> or <code>goto case</code> statement (that is, they are not allowed to fall-through to the next case).
The <code>default</code> case is not required to come last.
| <code>''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''</code>
|- valign="top"
| [[Windows PowerShell]]
| <code>if (''condition'') ''instruction''<br/>«else ''instructions''»</code>
| <code>if (''condition'') { ''instructions'' }<br/>elseif (''condition'') { ''instructions'' }<br/>''...''<br/>«else { ''instructions'' }»</code>
| <code>switch (''variable'') { ''case1''{''instructions'' «break;» } ''...'' «default { ''instructions'' }»}</code>
|
|- valign="top"
| [[Go (programming language)|Go]]
| <code>if ''condition'' {''instructions''}<br/>«else {''instructions''}»</code>
| <code>if ''condition'' {''instructions''}<br/>else if ''condition'' {''instructions''}<br/>''...''<br/>«else {''instructions''}»</code><br/>or<br/><code>switch { {{indent|2}}case ''condition'': ''instructions''{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br/>}</code>
| <code>switch ''variable'' { {{indent|2}}case ''case<sub>1</sub>'': ''instructions''{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br/>}</code>
|
|- valign="top"
| [[Swift (programming language)|Swift]]
| <code>if ''condition'' {''instructions''}<br/>«else {''instructions''}»</code>
| <code>if ''condition'' {''instructions''}<br/>else if ''condition'' {''instructions''}<br/>''...''<br/>«else {''instructions''}»</code>
| <code>switch ''variable'' { {{indent|2}}case ''case<sub>1</sub>'': ''instructions''{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br/>}</code>
|
|- valign="top"
| [[Perl]]
| <code>if (''condition'') {''instructions''}<br/>«else {''instructions''}»</code><br/>or<br/><code>unless (''notcondition'') {''instructions''}<br/>«else {''instructions''}»</code>
| <code>if (''condition'') {''instructions''}<br/>elsif (''condition'') {''instructions''}<br/>''...''<br/>«else {''instructions''}»</code><br/>or<br/><code>unless (''notcondition'') {''instructions''}<br/>elsif (''condition'') {''instructions''}<br/>''...''<br/>«else {''instructions''}»</code>
| <code>use feature "switch";<br/>''...''<br/>given (''variable'') { {{indent|2}}when (''case<sub>1</sub>'') { ''instructions'' }{{indent|2}}''...''{{indent|2}}«default { ''instructions'' }»<br/>}</code>
| <code>''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''</code>
|- valign="top"
| [[Raku (programming language)|Raku]]
| <code>if ''condition'' {''instructions''}<br/>«else {''instructions''}»</code><br/>or<br/><code>unless ''notcondition'' {''instructions''}</code>
| <code>if ''condition'' {''instructions''}<br/>elsif ''condition'' {''instructions''}<br/>...<br/>«else {''instructions''}</code>
| <code>given ''variable'' { {{indent|2}}when ''case<sub>1</sub>'' { ''instructions'' }{{indent|2}}''...''{{indent|2}}«default { ''instructions'' }»<br/>}</code>
| <code>''condition'' [[?:|??]] ''valueIfTrue'' !! ''valueIfFalse''</code>
|- valign="top"
| [[Ruby (programming language)|Ruby]]
| <code>if ''condition''{{indent|2}}''instructions''<br/>«else{{indent|2}}''instructions»''</code>
| <code>if ''condition''{{indent|2}}''instructions''<br/>elsif ''condition''{{indent|2}}''instructions''<br/>''...''<br/>«else{{indent|2}}''instructions''»<br/>end</code>
| <code>case ''variable''{{indent|2}}when ''case<sub>1</sub>''{{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}«else{{indent|4}}''instructions''»<br/>end</code>
| <code>''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''</code>
|- valign="top"
| [[Scala (programming language)|Scala]]
| <code>if (''condition'') {''instructions''}<br/>«else {''instructions''}»</code>
| <code>if (''condition'') {''instructions''}<br/>else if (''condition'') {''instructions''}<br/>...<br/>«else {''instructions''}»</code>
| <code>''expression'' match { {{indent|2}}case ''pattern1'' => ''expression''{{indent|2}}case ''pattern2'' => ''expression''{{indent|2}}''...''{{indent|2}}«case _ => ''expression''»<br/>}</code>{{ref|pattern matching|[b]}}
| <code>if (''condition'') ''valueIfTrue'' else ''valueIfFalse''</code>
|- valign="top"
| [[Smalltalk]]
| <code>''condition'' ifTrue:{{indent|2}}''trueBlock''<br/>«ifFalse:{{indent|2}}''falseBlock''»<br/>end</code>
|
|
| <code>''condition'' ifTrue: ''trueBlock'' ifFalse: ''falseBlock''</code>
|- valign="top"
| [[Common Lisp]]
| <code>''(when'' condition{{indent|2}}''instructions'')</code><br/>or<br/><code>(unless ''condition''{{indent|2}}''instructions'')</code><br/>or<br/><code>(if ''condition''{{indent|2}}(progn ''instructions''){{indent|2}}«(progn ''instructions'')»)</code>
| <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/>or<br/><code>(cond (''test1 value1'') (''test2 value2'') ''...''))</code>
|- valign="top"
| [[Scheme (programming language)|Scheme]]
| <code>(when ''condition instructions'')</code><br/>or<br/><code>(if ''condition'' (begin ''instructions'') «(begin ''instructions'')»)</code>
| <code>(cond (''condition1 instructions'') (''condition2 instructions'') ''...'' «(else ''instructions'')»)</code>
| <code>(case (''variable'') ((''case1'') ''instructions'') ((''case2'') ''instructions'') ''...'' «(else ''instructions'')»)</code>
| <code>(if ''condition valueIfTrue valueIfFalse'')</code>
|- valign="top"
| [[ISLISP]]
| <code>(if ''condition''{{indent|2}}(progn ''instructions''){{indent|2}}«(progn ''instructions'')»)</code>
| <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}}«(t ''instructions'')»)</code>
| <code>(if ''condition valueIfTrue valueIfFalse'')</code>
|- valign="top"
| [[Pascal (programming language)|Pascal]]
| <code>if ''condition'' then begin{{indent|2}}''instructions''<br/>end<br/>«else begin{{indent|2}}''instructions''<br/>end»'</code>{{ref|pascal semicolon|[c]}}
| <code>if ''condition'' then begin{{indent|2}}''instructions''<br/>end<br/>else if ''condition'' then begin{{indent|2}}''instructions''<br/>end<br/>''...''<br/>«else begin{{indent|2}}''instructions''<br/>end»</code>{{ref|pascal semicolon|[c]}}
| <code>case ''variable'' of{{indent|2}}''case1'': ''instructions''{{indent|2}}''...''{{indent|2}}«else: ''instructions''»<br/>end</code>{{ref|pascal semicolon|[c]}}
|- valign="top"
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=3| <code>If ''condition'' Then{{indent|2}}''instructions''<br/>«Else{{indent|2}}''instructions''»<br/>End If</code><br/>Single-line, when <code>instructions</code> are <code>instruction{{sub|1}} : instruction{{sub|2}} : ...</code>:<br/><code>If ''condition'' Then ''instructions'' «Else ''instructions»''</code>
| rowspan=3| <code>If ''condition'' Then{{indent|2}}''instructions''<br/>ElseIf ''condition'' Then{{indent|2}}''instructions''<br/>''...''<br/>«Else{{indent|2}}''instructions''»<br/>End If</code><br/>Single-line:<br/>See note about C-like languages; the <code>Else</code> clause of a single-line <code>If</code> statement can contain another single-line <code>If</code> statement.
| 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/>End Select</code>
| <code>[[IIf]](''condition'', ''valueIfTrue'', ''valueIfFalse'')</code>
|- valign="top"
| [[Visual Basic .NET]]
| rowspan=2| <code>If(''condition'', ''valueIfTrue'', ''valueIfFalse'')</code>
|- valign="top"
| [[Xojo]]
|- valign="top"
| [[Python (programming language)|Python]]{{ref|python indent|[a]}}
| <code>if ''condition'' :<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''</code>
| <code>if ''condition'' :<br/>{{keypress|Tab}}''instructions''<br/>elif ''condition'' :<br/>{{keypress|Tab}}''instructions''<br/>''...''<br/>«else:<br/>{{keypress|Tab}}''instructions»''</code>
| Python 3.10+:<br/><code>match ''variable'':<br/>{{keypress|Tab}}case ''case1'':<br/>{{keypress|Tab}}{{keypress|Tab}}''instructions''<br/>{{keypress|Tab}}case ''case2'':<br/>{{keypress|Tab}}{{keypress|Tab}}''instructions''</code>
| Python 2.5+:<br/><code>''valueIfTrue'' if ''condition'' else ''valueIfFalse''</code>
|- valign="top"
| [[S-Lang]]
| <code>if (''condition'') { ''instructions'' } «else { ''instructions'' }»</code>
| <code>if (''condition'') { ''instructions'' } else if (''condition'') { ''instructions'' } ''...'' «else { ''instructions'' }»</code>
| <code>switch (''variable'') { case ''case1'': ''instructions'' } { case ''case2'': ''instructions'' } ''...''</code>
|
|- valign="top"
| [[Fortran]]
| <code>IF (''condition'') THEN{{indent|2}}''instructions''<br/>ELSE{{indent|2}}''instructions''<br/>ENDIF</code>
| <code>IF (''condition'') THEN{{indent|2}}''instructions''<br/>ELSEIF (''condition'') THEN{{indent|2}}''instructions''<br/>''...''<br/>ELSE{{indent|2}}''instructions''<br/>ENDIF</code>
| <code>SELECT CASE(''variable''){{indent|2}}CASE (''case1''){{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}CASE DEFAULT{{indent|4}}''instructions''<br/>END SELECT</code>
|
|- valign="top"
| [[Forth (programming language)|Forth]]
| <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/>ENDCASE</code>
| <code>''condition'' IF ''valueIfTrue ''ELSE ''valueIfFalse'' THEN</code>
|- valign="top"
| [[OCaml]]
| <code>if ''condition'' then begin ''instructions'' end «else begin ''instructions'' end»</code>
| <code>if ''condition'' then begin ''instructions'' end else if ''condition'' then begin ''instructions'' end ''...'' «else begin ''instructions'' end»</code>
| rowspan=2| <code>match ''value'' with {{indent|2}}''pattern1'' -> ''expression''{{indent|2}}{{pipe}} ''pattern2'' -> ''expression''{{indent|2}}''...''{{indent|2}}«{{pipe}} _ -> ''expression''»</code>{{ref|pattern matching|[b]}}
| rowspan=4| <code>if ''condition'' then ''valueIfTrue'' else ''valueIfFalse''</code>
|- valign="top"
| [[F Sharp (programming language)|F#]]
| Lightweight syntax mode:
Either on a single line or with indentation as shown below:
<code>if ''condition'' then<br/>{{keypress|Tab}}''instructions''<br/>«else<br/>{{keypress|Tab}}''instructions»''</code><br/>Verbose syntax mode:<br/>Same as Standard ML.
| Lightweight syntax mode:<br/>Either on a single line or with indentation as shown below:<br/><code>if ''condition'' then<br/>{{keypress|Tab}}''instructions''<br/>elif ''condition'' then<br/>{{keypress|Tab}}''instructions''<br/>''...''<br/>«else<br/>{{keypress|Tab}}''instructions»''</code><br/>Verbose syntax mode:<br/>Same as Standard ML.
|- valign="top"
| [[Standard ML]]
| <code>if ''condition'' then «(''»instructions «'')»<br/>else «(''» instructions «'')»</code>
| <code>if ''condition'' then «(''»instructions «'')»<br/>else if ''condition'' then «(''» instructions «'')»<br/>''...''<br/>else «(''» instructions «'')»</code>
| <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"
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| <code>if ''condition'' then ''expression'' else ''expression''</code><br/>or<br/><code>when ''condition'' (do ''instructions'')</code><br/>or<br/><code>unless ''notcondition'' (do ''instructions'')</code>
| <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/>}</code>{{ref|pattern matching|[b]}}
|- valign="top"
| [[Bash shell]]
| <code>if ''condition-command;'' then{{indent|2}}''expression''<br/>«else{{indent|2}}''expression''»<br/>fi</code>
| <code>if ''condition-command;'' then{{indent|2}}''expression''<br/>elif ''condition-command;'' then{{indent|2}}''expression''<br/>«else{{indent|2}}''expression''»<br/>fi</code>
| <code>case ''"$variable"'' in{{indent|2}}''"$condition1" ){{indent|4}}command...{{indent|2}}"$condition2" ){{indent|4}}command...''<br/>esac</code>
|
|- valign="top"
| [[CoffeeScript]]
| <code>if ''condition'' then ''expression'' «else ''expression»''</code><br/>or<br/><code>if ''condition{{indent|2}}expression''<br/>«else{{indent|2}}''expression»''</code><br/>or<br/><code>''expression'' if ''condition''</code><br/>or<br/><code>unless ''condition''{{indent|2}}''expression''<br/>«else{{indent|2}}''expression»''</code><br/>or<br/><code>''expression'' unless ''condition''</code>
| <code>if ''condition'' then ''expression'' else if ''condition'' then ''expression'' «else ''expression»''</code><br/>or<br/><code>if ''condition''{{indent|2}}''expression''<br/>else if ''condition{{indent|2}}expression''<br/>«else{{indent|2}}''expression»''</code><br/>or<br/><code>unless ''condition''{{indent|2}}''expression''<br/>else unless ''condition{{indent|2}}expression''<br/>«else{{indent|2}}''expression»''</code>
| <code>switch ''expression''{{indent|2}}when ''condition'' then ''expression''{{indent|2}}else ''expression''</code><br/>or<br/><code>switch ''expression''{{indent|2}}when ''condition''{{indent|4}}''expression''{{indent|2}}«else{{indent|4}}''expression»''</code>
| All conditions are expressions.
|- valign="top"
| [[COBOL]]
| <code>IF ''condition'' «THEN»{{indent|2}}''expression''<br/>«ELSE{{indent|2}}''expression»''.</code>{{ref|COBOL END-IF|[d]}}
|
| <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/>END-EVALUATE</code>
|
|- valign="top"
| [[Rust (programming language)|Rust]]
| <code>if ''condition'' { {{indent|2}}''expression''<br/>}« else { {{indent|2}}''expression''<br/>}»</code>
| <code>if ''condition'' { {{indent|2}}''expression''<br/>} else if ''condition'' {''{{indent|2}}expression<br/>''}« else {''{{indent|2}}expression<br/>''}''»''</code>
| <code>match ''variable'' { {{indent|2}}''pattern1'' => ''expression,''{{indent|2}}''pattern2'' => ''expression,''{{indent|2}}''pattern3'' => ''expression,''{{indent|2}}«_ => ''expression''»<br/>}</code>{{ref|pattern matching|[b]}}{{ref|Rust match expression|[e]}}
| All conditions are expressions
|- valign="top"
!
! if
! else if
! [[switch statement|select case]]
! [[Conditional (programming)#If expressions|conditional expression]]
|}
 
* {{note|python indent|a}} A single instruction can be written on the same line following the colon. Multiple instructions are grouped together in a [[block (programming)|block]] which starts on a newline (The indentation is required). The conditional expression syntax does not follow this rule.
* {{note|pattern matching|b}} This is [[pattern matching]] and is similar to select case but not the same. It is usually used to deconstruct [[algebraic data type]]s.
* {{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 (<code>,</code>) at the end of a match arm can be omitted after the last match arm, or after any match arm in which the expression is a block (ends in possibly empty matching brackets <code>{}</code>).
 
=== [[Control flow#Loops|Loop statements]] ===
{| class="wikitable sortable"
|-
!
| C
! [[while loop]]
| if (''condition'') { ''instructions'' } else { ''instructions'' }
! [[do while loop]]
| if (''condition'') { ''instructions'' } else if (''condition'') { ''instructions'' }
! [[for loop|(count-controlled) for loop]]
| while (''condition'') { ''instructions'' }
! [[foreach]]
| do { ''instructions'' } while (''condition'')
| for (i = 0; i<N; i++) { ''instructions'' }
| switch (''variable'') { case ''case1'': ''instructions'' break; ... default: ''instructions'';}
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| C++ (STL)
| <code>while ''condition'' loop{{indent|2}}''statements''<br/>end loop</code>
| as above
| <code>loop{{indent|2}}''statements''{{indent|2}}exit when not ''condition''<br/>end loop</code>
| as above
| <code>for ''index'' in «reverse» ''[first'' .. ''last {{pipe}} discrete_type]'' loop{{indent|2}}''statements''<br/>end loop</code>
| as above
| <code>for ''item'' of «reverse» ''iterator'' loop{{indent|2}}''statements''<br/>end loop</code><br/>or<br/><code>(for [all {{pipe}} some] [in {{pipe}} of] ''[first'' .. ''last {{pipe}} discrete_type {{pipe}} iterator]'' => ''predicate'')</code>{{ref|Ada_quantifiers|[b]}}
| as above
| as above
| as above
|-
| rowspan=2| [[ALGOL 68]] || colspan=3 align=center| <code>«for ''index''» «from ''first''» «by ''increment''» «to ''last''» «while ''condition''» do ''statements'' od</code>
| Java
| rowspan=2| <code>for key «to upb list» do «typename val=list[key];» ''statements'' od</code>
| as above
| as above
| as above
| as above
| as above
| as above
|-
| <code>«while ''condition''»{{indent|2}}do ''statements'' od</code>
| Pascal
| if<code>«while ''statements; condition'' then begin \n»{{indent|2}}do ''instructionsstatements'' \n end;od</code>
| <code>«for ''index''» «from ''first''» «by ''increment''» «to ''last''» do ''statements'' od</code>
| if ''condition'' then begin \n ''instructions'' \n end\n else begin \n ''instructions'' \n end;
|-
| [[APL (programming language)|APL]]
| <code>:While ''condition''{{indent|2}}''statements''<br/>:EndWhile</code>
| <code>:Repeat{{indent|2}}''statements''<br/>:Until ''condition''</code>
| <code>:For ''var«s»'' :In ''list''{{indent|2}}''statements''<br/>:EndFor</code>
| <code>:For ''var«s»'' :InEach ''list''{{indent|2}}''statements''<br/>:EndFor</code>
|-
| [[C (programming language)|C]] ([[C99]])
| rowspan=9| <code>instructions</code> can be a single statement or a block in the form of: <code>{ ''statements'' }</code><br/><code>while (''condition'') ''instructions''</code>
| rowspan=9| <code>do ''instructions'' while (''condition'');</code>
| rowspan=5| <code>for (''«type» i'' = ''first''; ''i'' <= ''last''; ''i''++) ''instructions''</code>
| {{n/a}}
|-
| [[Objective-C]]
| <code>for (''type item'' in ''set'') ''instructions''</code>
|-
| [[C++]] (STL)
| <code>«std::»for_each(''start'', ''end'', ''function'')</code><br/>Since [[C++11]]:<br/><code>for (''type item'' : ''set'') ''instructions''</code>
|-
| [[C Sharp (programming language)|C#]]
| <code>foreach (''type item'' in ''set'') ''instructions''</code>
|-
| [[Java (programming language)|Java]]
| <code>for (''type item'' : ''set'') ''instructions''</code>
|-
| [[JavaScript]]
| <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>
<code>for (var ''item'' of ''set'') ''instructions''</code>
|-
| [[PHP]]
| <code>foreach (range(''first'', ''last'') as $i) ''instructions''</code><br/>or<br/><code>for ($i = ''first''; $i <= ''last''; $i++) ''instructions''</code>
| <code>foreach (''set'' as ''item'') ''instructions''</code><br/>or<br/><code>foreach (''set'' as ''key'' => ''item'') ''instructions''</code>
|-
| [[Windows PowerShell]]
| <code>for ($i = ''first''; $i -le ''last''; $i++) ''instructions''</code>
| <code>foreach (''item'' in ''set'') ''instructions''</code>
|-
| [[D (programming language)|D]]
| <code>foreach ''(i;'' first ''...'' last) ''instructions''</code>
| <code>foreach ''(«type» item; set) instructions''</code>
|-
| [[Go (programming language)|Go]]
| <code>for ''condition'' { ''instructions'' }</code>
|
| <code>for ''i'' := ''first''; ''i'' <= ''last''; ''i''++ { ''instructions'' }</code>
| repeat \n ''instructions'' \n until ''condition'';
| <code>for i''key'', ''item'' := 1range to''set'' N do \n begin \n{ ''instructions'' \n end;}</code>
| case ''variable'' of \n ''meaning'': ''instructions''; \n default: ''instructions'' \n ... end;
|-
| [[Swift (programming language)|Swift]]
| Visual Basic
| If<code>while ''condition'' Then \n{ ''instructions'' \n Else ''instructions'' \n End If}</code>
| If2.x:<br/><code>repeat ''condition'' Then \n{ ''instructions'' \n} ElseIfwhile ''condition''</code><br/>1.x:<br/><code>do Then \n{ ''instructions'' \n} Elsewhile ''instructionscondition'' \n End If</code>
| <code>for ''i'' = ''first'' ... ''last'' { ''instructions'' }</code><br/>or<br/><code>for ''i'' = ''first'' ..< ''last''+1 { ''instructions'' }</code><br/>or<br/><code>for var ''i'' = ''first''; ''i'' <= ''last''; ''i''++ { ''instructions'' }</code>
| Do While ''condition'' \n ''instructions'' \n Loop
| <code>for ''item'' in ''set'' { ''instructions'' }</code>
| Do \n ''instructions'' \n Loop While ''condition''
| For i = 1 To N Step 1 \n ''instructions'' \n Next i
| Select Case ''variable'' \n Case ''case1'' \n ''statements'' \n ... Case Else \n Statements \n End select
|-
| [[Perl]]
| Python
| if<code>while (''condition'') : \n \t{ ''instructions'' \n}</code><br/>or<br/><code>until else:(''notcondition'') \n{ \t''instructions'' \n}</code>
| <code>do { ''instructions'' } while (''condition'')</code><br/>or<br/><code>do { ''instructions'' } until (''notcondition'')</code>
|
| <code>for«each» «$i» (''first'' .. ''last'') { ''instructions'' }</code><br/>or<br/><code>for ($i = ''first''; $i <= ''last''; $i++) { ''instructions'' }</code>
|
| <code>for«each» ''«$item»'' (''set'') { ''instructions'' }</code>
|
|-
| for i in range(1, N): \n \t ''instructions'' \n
| [[Raku (programming language)|Raku]]
| <code>while ''condition'' { ''instructions'' }</code><br/>or<br/><code>until ''notcondition'' { ''instructions'' }</code>
| <code>repeat { ''instructions'' } while ''condition''</code><br/>or<br/><code>repeat { ''instructions'' } until ''notcondition''</code>
| <code>for ''first''..''last'' -> $i { ''instructions'' }</code><br/>or<br/><code>loop ($i = ''first''; $i <=''last''; $i++) { ''instructions'' }</code>
| <code>for ''set«'' -> ''$item»'' { ''instructions'' }</code>
|-
| [[Ruby (programming language)|Ruby]]
| <code>while ''condition''{{indent|2}}''instructions''<br/>end</code><br/>or<br/><code>until ''notcondition''{{indent|2}}''instructions''<br/>end</code>
| <code>begin{{indent|2}}''instructions''<br/>end while ''condition''</code><br/>or<br/><code>begin{{indent|2}}''instructions''<br/>end until ''notcondition''</code>
| <code>for i in ''first''..''last''{{indent|2}}''instructions''<br/>end</code><br/>or<br/><code>for i in ''first''...''last+1''{{indent|2}}''instructions''<br/>end</code><br/>or<br/><code>''first''.{{not a typo|upto}}(''last'') { {{pipe}}i{{pipe}} ''instructions'' }</code>
| <code>for ''item'' in ''set''{{indent|2}}''instructions''<br/>end</code><br/>or<br/><code>''set''.each { {{pipe}}''item''{{pipe}} ''instructions'' }</code>
|-
| [[Bash shell]]
| <code>while ''condition ;''do{{indent|2}}''instructions''<br/>done</code><br/>or<br/><code>until ''notcondition ;''do{{indent|2}}''instructions''<br/>done</code>
| {{n/a}}
| <code>for ((''i'' = ''first''; ''i'' <= ''last''; ++''i'')) ; do{{indent|2}}''instructions''<br/>done</code>
| <code>for ''item'' in ''set ;''do{{indent|2}}''instructions''<br/>done</code>
|-
| [[Scala (programming language)|Scala]]
| <code>while (''condition'') { ''instructions'' }</code>
| <code>do { ''instructions'' } while (''condition'')</code>
| <code>for (''i'' <- ''first'' to ''last'' «by 1») { ''instructions'' }</code><br/>or<br/><code>''first'' to ''last'' «by 1» foreach (''i'' => { ''instructions'' })</code>
| <code>for (''item'' <- ''set'') { ''instructions'' }</code><br/>or<br/><code>''set'' foreach (''item'' => { ''instructions'' })</code>
|-
| [[Smalltalk]]
| <code>''conditionBlock'' whileTrue:{{indent|2}}''loopBlock''</code>
| <code>''loopBlock'' doWhile:{{indent|2}}''conditionBlock''</code>
| <code>''first'' to: ''last'' do:{{indent|2}}''loopBlock''</code>
| <code>''collection'' do:{{indent|2}}''loopBlock''</code>
|-
| [[Common Lisp]]
| <code>(loop{{indent|2}}while ''condition''{{indent|2}}do{{indent|2}}''instructions'')</code><br/>or<br/><code>(do () (''notcondition''){{indent|2}}''instructions'')</code>
| <code>(loop{{indent|2}}do{{indent|2}}''instructions''{{indent|2}}while ''condition'')</code>
| <code>(loop{{indent|2}}for i from ''first'' to ''last «by 1»''{{indent|2}}do{{indent|2}}''instructions'')</code><br/>or<br/><code>(dotimes (i N){{indent|2}}''instructions'')</code><br/>or<br/><code>(do ((i ''first'' {{codett|2=lisp|1=(1+ i))) ((>=i}} ''last''))<br/>{{indent|2}}''instructions'')</code>
| <code>(loop{{indent|2}}for ''item'' in ''list''{{indent|2}}do{{indent|2}}''instructions'')</code><br/>or<br/><code>(loop{{indent|2}}for ''item'' across ''vector''{{indent|2}}do{{indent|2}}''instructions'')</code><br/>or<br/><code>(dolist (''item list''){{indent|2}}''instructions'')</code><br/>or<br/><code>(mapc ''function list'')</code><br/>or<br/><code>(map ''type function sequence'')</code>
|-
| [[Scheme (programming language)|Scheme]]
| <code>(do () (''notcondition'') ''instructions'')</code><br/>or<br/><code>{{codett|2=scheme|(let loop () (if}} ''condition'' (begin ''instructions'' (loop))))</code>
| <code>{{codett|2=scheme|(let loop () (}}''instructions'' (if ''condition'' (loop))))</code>
| <code>(do ((i ''first'' {{codett|2=scheme|1=(+ i 1))) ((>= i}} ''last'')) ''instructions'')</code><br/>or<br/><code>{{codett|2=scheme|(let loop ((i}} ''first''{{codett|2=scheme|1)) (if (< i}} ''last'') (begin ''instructions'' {{codett|2=scheme|(loop (+ i 1)))))}}</code>
| <code>{{codett|2=scheme|(for-each (lambda (}}''item'') ''instructions'') ''list'')</code>
|-
| [[ISLISP]]
| <code>(while ''condition instructions'')</code>
| <code>{{codett|2=lisp|1=(tagbody loop}} ''instructions'' (if ''condition'' {{codett|2=lisp|1=(go loop))}}</code>
| <code>{{codett|2=lisp|1=(for ((i}} ''first'' {{codett|2=lisp|1=(+ i 1))) ((>= i}} ''last'')) ''instructions'')</code>
| <code>{{codett|2=lisp|1=(mapc (lambda (}}''item'') ''instructions'') ''list'')</code>
|-
| [[Pascal (programming language)|Pascal]]
| <code>while ''condition'' do begin{{indent|2}}''instructions''<br/>end</code>
| <code>repeat{{indent|2}}''instructions''<br/>until ''notcondition'';</code>
| <code>for ''i'' := ''first'' «step 1» to ''last'' do begin{{indent|2}}''instructions''<br/>end;</code>{{ref|step|[a]}}
| <code>for ''item'' in ''set'' do ''instructions''</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=2| <code>Do While ''condition''{{indent|2}}''instructions''<br/>Loop</code><br/>or<br/><code>Do Until ''notcondition''{{indent|2}}''instructions''<br/>Loop</code><br/>or<br/><code>While ''condition''{{indent|2}}''instructions''<br/>Wend</code> (Visual Basic .NET uses <code>End While</code> instead)
| rowspan=2| <code>Do{{indent|2}}''instructions''<br/>Loop While ''condition''</code><br/>or<br/><code>Do{{indent|2}}''instructions''<br/>Loop Until ''notcondition''</code>
| <code>i</code> must be declared beforehand.
<code>For ''i'' = ''first'' To ''last'' «Step ''1»{{indent|2}}instructions''<br/>Next i</code>
| <code>For Each ''item'' In ''set''{{indent|2}}''instructions''<br/>Next ''item''</code>
|-
| [[Visual Basic .NET]]
| rowspan=2| <code>For i« As ''type»'' = ''first'' To ''last«'' Step ''1»{{indent|2}}instructions''<br/>Next« i»</code>{{ref|step|[a]}}
| rowspan=2| <code>For Each ''item«'' As ''type»'' In ''set''{{indent|2}}''instructions''<br/>Next''« item»''</code>
|-
| [[Xojo]]
| <code>While ''condition''{{indent|2}}''instructions''<br/>Wend</code>
| <code>Do Until ''notcondition''{{indent|2}}''instructions''<br/>Loop</code><br/>or<br/><code>Do{{indent|2}}''instructions''<br/>Loop Until ''notcondition''</code>
|-
| [[Python (programming language)|Python]]
| <code>while ''condition'' :<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''</code>
| {{n/a}}
| Python 3.x:<br/><code>for i in range(''first'', ''last+1''):<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''</code><br/>Python 2.x:<br/><code>for i in xrange(''first'', ''last+1''):<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''</code>
| <code>for ''item'' in ''set'':<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''</code>
|-
| [[S-Lang]]
| <code>while (''condition'') { ''instructions'' } «then ''optional-block»''</code>
| <code>do { ''instructions'' } while (''condition'') «then ''optional-block»''</code>
| <code>for (i = ''first''; i <= ''last''; i++) { ''instructions'' } «then ''optional-block»''</code>
| <code>foreach ''item''(''set'') «using (''what'')» { ''instructions'' } «then ''optional-block»''</code>
|-
| [[Fortran]]
| <code>DO WHILE (''condition''){{indent|2}}''instructions''<br/>ENDDO</code>
| <code>DO{{indent|2}}''instructions''{{indent|2}}IF (''condition'') EXIT<br/>ENDDO</code>
| <code>DO ''I'' = ''first'',''last''{{indent|2}}''instructions''<br/>ENDDO</code>
| {{n/a}}
|-
| [[Forth (programming language)|Forth]]
| <code>BEGIN ''«instructions» condition'' WHILE ''instructions'' REPEAT</code>
| <code>BEGIN '' instructions condition'' UNTIL</code>
| <code>''limit start'' DO ''instructions'' LOOP</code>
| {{n/a}}
|-
| [[OCaml]]
| <code>while ''condition'' do ''instructions'' done</code>
| {{n/a}}
| <code>for i = ''first'' to ''last'' do ''instructions'' done</code>
| <code>Array.iter (fun ''item'' -> ''instructions'') ''array''</code><br/>or<br/><code>List.iter (fun ''item'' -> ''instructions'') ''list''</code>
|-
| [[F Sharp (programming language)|F#]]
| <code>while ''condition'' do<br/>{{keypress|Tab}}''instructions''</code>
| {{n/a}}
| <code>for i = ''first'' to ''last'' do<br/>{{keypress|Tab}}''instructions''</code>
| <code>for''item'' in ''set'' do<br/>{{keypress|Tab}}''instructions''</code><br/>or<br/><code>Seq.iter (fun ''item'' -> ''instructions'') ''set''</code>
|-
| [[Standard ML]]
| <code>while ''condition'' do ( ''instructions'' )</code>
| colspan=2 {{n/a}}
| <code>Array.app (fn ''item'' => ''instructions'') ''array''</code><br/>or<br/><code>app (fn ''item'' => ''instructions'') ''list''</code>
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| colspan=2 {{n/a}}
| <code>Control.Monad.forM_ [''first''..''last''] (\i -> do ''instructions'')</code>
| <code>Control.Monad.forM_''list'' (\item -> do ''instructions'')</code>
|-
| [[Eiffel (programming language)|Eiffel]]
| colspan=4| <code>from{{indent|2}}''setup''<br/>until{{indent|2}}''condition''<br/>loop{{indent|2}}''instructions''<br/>end</code>
|-
| [[CoffeeScript]]
| <code>while ''condition''{{indent|2}}''expression''</code><br/>or<br/><code>''expression'' while ''condition''</code><br/>or<br/><code>while ''condition'' then ''expression''</code><br/>or<br/><code>until ''condition''{{indent|2}}''expression''</code><br/>or<br/><code>''expression'' until ''condition''</code><br/>or<br/><code>until ''expression'' then ''condition''</code>
| {{n/a}}
| <code>for ''i'' in [''first''..''last'']{{indent|2}}''expression''</code><br/>or<br/ ><code>for ''i'' in [''first''..''last''] then ''expression''</code><br/>or<br/><code>''expression'' for ''i'' in [''first''..''last'']</code>
| <code>for ''item'' in ''set''{{indent|2}}''expression''</code><br/>or<br/><code>for ''item'' in ''set'' then ''expression''</code><br/>or<br/><code>''expression'' for ''item'' in ''set''</code>
|-
| [[COBOL]]
| <code>PERFORM ''procedure-1'' «THROUGH ''procedure-2''» ««WITH» TEST BEFORE» UNTIL ''condition''</code>{{ref|COBOL THRU|[c]}}<br/>or<br/><code>{{codett|2=cobolfree|PERFORM ««WITH» TEST BEFORE» UNTIL}} ''condition''{{indent|2}}''expression''<br/>END-PERFORM</code>
| <code>PERFORM ''procedure-1'' «THROUGH ''procedure-2''» «WITH» TEST AFTER UNTIL ''condition''</code>{{ref|COBOL THRU|[c]}}<br/>or<br/><code>{{codett|2=cobolfree|PERFORM «WITH» TEST AFTER UNTIL}} ''condition''{{indent|2}}''expression''<br/>END-PERFORM</code>
| <code>PERFORM ''procedure-1'' «THROUGH ''procedure-2»'' VARYING ''i'' FROM ''first'' BY ''increment'' UNTIL ''i'' > ''last''</code>{{ref|COBOL GREATER THAN|[d]}}<br/>or<br/><code>PERFORM VARYING ''i'' FROM ''first'' BY ''increment'' UNTIL ''i'' > ''last''{{indent|2}}''expression''<br/>END-PERFORM</code>{{ref|COBOL GREATER THAN|[d]}}
| {{n/a}}
|-
| [[Rust (programming language)|Rust]]
| <code>while ''condition'' { {{indent|2}}''expression''<br/>}</code>
| <code>loop { {{indent|2}}''expression''{{indent|4}}if ''condition'' { {{indent|6}}break;{{indent|2}}}<br/>}</code>
| <code>for i in ''first''..''last+1'' { {{indent|2}}''expression''<br/>}</code><br/>or<br/><code>for i in ''first''..=''last'' { {{indent|2}}''expression''<br/>}</code>
| <code>for ''item'' in ''set'' { {{indent|2}}''expression''<br/>}</code>{{ref|Rust FOREACH|[e]}}<br/>or<br/><code>''set''.into_iter().for_each({{pipe}}''item''{{pipe}} expression);</code>{{ref|Rust FOREACH|[e]}}
|}
 
* {{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 {{math|&forall;}}) as well as the [[existential quantifier]] ("there exists" or {{math|&exist;}}).
* {{note|COBOL THRU|c}} <code>THRU</code> may be used instead of <code>THROUGH</code>.
* {{note|COBOL GREATER THAN|d}} {{code|2=cobolfree|«IS» GREATER «THAN»}} may be used instead of <code>></code>.
* {{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"
|-
!
! throw
! handler
! assertion
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>raise ''exception_name'' «with ''string_expression»''</code>
| <code>begin{{indent|2}}''statements''<br/>exception{{indent|2}}when ''exception_list<sub>1</sub>'' <nowiki>=></nowiki> ''statements;''{{indent|2}}when ''exception_list<sub>2</sub>'' <nowiki>=></nowiki> ''statements;''<br/>''...''{{indent|2}}«when others <nowiki>=></nowiki> ''statements;''»<br/>end</code>{{ref|Ada_uncaught_exceptions|[b]}}
| <code>{{codett|2=ada|1=pragma Assert}} («Check <nowiki>=></nowiki>» ''boolean_expression'' ««Message =>» ''string_expression''»)<br/>''[function {{pipe}} procedure {{pipe}} entry]'' with{{indent|2}}Pre <nowiki>=></nowiki> ''boolean_expression''{{indent|2}}Post <nowiki>=></nowiki> ''boolean_expression''<br/>''any_type'' with Type_Invariant <nowiki>=></nowiki> ''boolean_expression''</code>
|-
| [[APL (programming language)|APL]]
| <code>''«string_expression»'' ⎕SIGNAL ''number_expression''</code>
| <code>:Trap ''number«s»_expression''{{indent|2}}''statements''<br/>«:Case ''number«s»_expression''{{indent|2}}''statements''»<br/>''...''<br/>«:Else ''number«s»_expression''{{indent|2}}''statements''»<br/>:EndTrap</code>
| <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: ''instructions'' break; case ''exception'': ''instructions'' ... }</code>
| rowspan=2|<code>assert(''condition'');</code>
|-
| [[C++]]
| rowspan=8|<code>throw ''exception'';</code>
| <code>try { ''instructions'' } catch «(''exception'')» { ''instructions'' } ''...''</code>
|-
| [[C Sharp (programming language)|C#]]
| <code>try { ''instructions'' } catch «(''exception« name»'')» { ''instructions'' } ''...'' «finally { ''instructions'' }»</code>
| <code>System.Diagnostics.Debug.Assert(''condition'');</code><br/>or<br/><code>System.Diagnostics.Trace.Assert(''condition'');</code>
|-
| [[Java (programming language)|Java]]
| <code>try { ''instructions'' } catch (''exception'') { ''instructions'' } ''...'' «finally { ''instructions'' }»</code>
| <code>assert ''condition'' «: ''description''»;</code>
|-
| [[JavaScript]]
| <code>try { ''instructions'' } catch (''exception'') { ''instructions''} «finally { ''instructions'' }»</code>
| {{dunno}}
|-
| [[D (programming language)|D]]
| <code>try { ''instructions'' } catch (''exception'') { ''instructions'' } ''...'' «finally { ''instructions'' }»</code>
| <code>assert(''condition'');</code>
|-
| [[PHP]]
| <code>try { ''instructions'' } catch (''exception'') { ''instructions'' } ''...'' «finally { ''instructions'' }»</code>
| <code>assert(''condition'');</code>
|-
| [[S-Lang]]
| <code>try { ''instructions'' } catch ''«exception»'' { ''instructions'' } ''...'' «finally { ''instructions'' }»</code>
| {{dunno}}
|-
| [[Windows PowerShell]]
| <code>trap «[''exception'']» { ''instructions'' } ''... instructions''</code><br/>or<br/><code>try { ''instructions'' } catch «[''exception'']» { ''instructions'' } ''...'' «finally { ''instructions'' }»</code>
| <code>{{codett|[Debug]::Assert(|ps1}}''condition'')</code>
|-
| [[Objective-C]]
| <code>@throw ''exception'';</code>
| <code>@try { ''instructions'' } @catch (''exception'') { ''instructions'' } ''...'' «@finally { ''instructions'' }»</code>
| <code>NSAssert(''condition'', ''description'');</code>
|-
| [[Swift (programming language)|Swift]]
| <code>throw ''exception''</code> (2.x)
| <code>do { try ''expression'' ... ''instructions'' } catch ''exception'' { ''instructions'' } ''...''</code> (2.x)
| <code>assert(''condition''«, ''description''»)</code>
|-
| [[Perl]]
| rowspan=2| <code>die ''exception'';</code>
| <code>eval { ''instructions'' {{codett|}; if ($@) {|perl}} ''instructions'' }</code>
| {{dunno}}
|-
| [[Raku (programming language)|Raku]]
| <code>try { ''instructions'' CATCH { when ''exception'' { ''instructions'' } ''...''}}</code>
| {{dunno}}
|-
| [[Ruby (programming language)|Ruby]]
| <code>raise ''exception''</code>
| <code>begin{{indent|2}}''instructions''<br/>rescue ''exception''{{indent|2}}''instructions''<br/>''...''<br/>«else{{indent|2}}''instructions''»<br/>«ensure{{indent|2}}''instructions''»<br/>end</code>
|
|-
| [[Smalltalk]]
| [[S-Lang_(programming_language)|S-Lang]]
| <code>''exception'' raise</code>
| if (''condition'') { ''instructions'' } else { ''instructions'' }
| <code>''instructionBlock'' on: ''exception'' do: ''handlerBlock''</code>
| if (''condition'') { ''instructions'' } else if (''condition'') { ''instructions'' }
| <code>assert: ''conditionBlock''</code>
| while (''condition'') { ''instructions'' }
|-
| [[Common Lisp]]
| <code>(error ''"exception"'')</code><br/>or<br/><code>(error{{indent|2}}''type''{{indent|2}}''arguments'')</code><br/>or<br/><code>(error (make-condition{{indent|2}}''type''{{indent|2}}''arguments''))</code>
| <code>(handler-case{{indent|2}}(progn ''instructions''){{indent|2}}(''exception instructions''){{indent|2}}''...'')</code><br/>or<br/><code>(handler-bind{{indent|2}}(''condition''{{indent|4}}(lambda{{indent|4}}''instructions''{{indent|4}}«invoke-restart ''restart args»''))<br/>''...'')</code>{{ref|a|[a]}}
| <code>(assert ''condition'')</code><br/>or<br/><code>(assert ''condition''{{indent|2}}«(''place''){{indent|2}}''«error»»'')</code><br/>or<br/><code>(check-type ''var type'')</code>
|-
| [[Scheme (programming language)|Scheme]] ([[R6RS|R<sup>6</sup>RS]])
| <code>(raise ''exception'')</code>
| <code>(guard (con (''condition instructions'') ''...'') ''instructions'')</code>
| {{dunno}}
|-
| [[ISLISP]]
| <code>(error ''"error-string" objects'')</code><br/>or<br/><code>(signal-condition ''condition continuable'')</code>
| <code>(with-handler{{indent|2}}''handler form*''<br/>)</code>
| {{dunno}}
|-
| [[Pascal (programming language)|Pascal]]
| <code>raise ''Exception.Create()''</code>
| <code>try ''Except'' on ''E: exception'' do begin ''instructions'' end; end;</code>
| {{dunno}}
|-
| [[Visual Basic (classic)|Visual Basic]]
| <code>Err.Raise ''ERRORNUMBER''</code>
| <code>{{codett|2=vbnet|With New}} ''Try''{{codett|2=vbnet|: On Error Resume Next}}{{indent|2}}''OneInstruction<br/>.Catch''{{codett|2=vbnet|: On Error GoTo 0: Select Case}} ''.Number''{{indent|2}}Case ''SOME_ERRORNUMBER''{{indent|4}}''instructions''<br/>{{codett|2=vbnet|End Select: End With}}</code><syntaxhighlight lang="vbnet">
'*** Try class ***
Private mstrDescription As String
Private mlngNumber As Long
 
Public Sub Catch()
mstrDescription = Err.Description
mlngNumber = Err.Number
End Sub
 
Public Property Get Number() As Long
Number = mlngNumber
End Property
 
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 ''condition''</code>
|-
| [[Visual Basic .NET]]
| <code>Throw ''exception''</code><br/>or<br/><code>Error ''errorcode''</code>
| <code>Try{{indent|2}}''instructions''<br/>Catch« ''name'' As ''exception''»« When ''condition''»{{indent|2}}''instructions''<br/>''...''<br/>«Finally{{indent|2}}''instructions''»<br/>End Try</code>
| <code>System.Diagnostics.<wbr/>Debug.Assert(''condition'')</code><br/>or<br/><code>System.Diagnostics.<wbr/>Trace.Assert(''condition'')</code>
|-
| [[Xojo]]
| <code>Raise ''exception''</code>
| <code>Try{{indent|2}}''instructions''<br/>Catch ''«exception»''{{indent|2}}''instructions''<br/>''...''<br/>«Finally{{indent|2}}''instructions''»<br/>End Try</code>
| {{n/a}}
|-
| [[Python (programming language)|Python]]
| <code>raise ''exception''</code>
| <code>try:<br/>{{keypress|Tab}}''instructions''<br/>except ''«exception»'':<br/>{{keypress|Tab}}''instructions''<br/>''...''<br/>«else:<br/>{{keypress|Tab}}''instructions''»<br/>«finally:<br/>{{keypress|Tab}}''instructions»''</code>
| <code>assert ''condition''</code>
|-
| [[Fortran]]
| colspan=3 {{n/a}}
|-
| [[Forth (programming language)|Forth]]
| <code>''code'' THROW</code>
| <code>''xt'' CATCH ''( code or 0 )''</code>
| {{n/a}}
|-
| [[OCaml]]
| rowspan=2| <code>raise ''exception''</code>
| <code>try ''expression'' with ''pattern'' -> ''expression ...''</code>
| rowspan=2| <code>assert ''condition''</code>
|-
| [[F Sharp (programming language)|F#]]
| <code>try ''expression'' with ''pattern'' -> ''expression ...''</code><br/>or<br/><code>try ''expression'' finally ''expression''</code>
|-
| [[Standard ML]]
| <code>raise ''exception «arg»''</code>
| <code>''expression'' handle ''pattern'' => ''expression ...''</code>
|
|-
| for (i = 0; i<N; i++) { ''instructions'' }
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| switch (''variable'') { case ''case1'': ''instructions'' } { case ''case2'': ''instructions'' } ...
| <code>throw ''exception''</code><br/>or<br/><code>throwError ''expression''</code>
| <code>catch ''tryExpression catchExpression''</code><br/>or<br/><code>catchError ''tryExpression catchExpression''</code>
| <code>assert ''condition expression''</code>
|-
| [[COBOL]]
| <code>{{codett|2=cobolfree|RAISE «EXCEPTION»}} ''exception''</code>
| <code>{{codett|2=cobolfree|USE «AFTER» EXCEPTION OBJECT}} ''class-name''.</code><br/>or<br/><code>{{codett|2=cobolfree|USE «AFTER» EO}} ''class-name''.</code><br/>or<br/><code>{{codett|2=cobolfree|USE «AFTER» EXCEPTION CONDITION}} ''exception-name'' «FILE ''file-name»''.</code><br/>or<br/><code>{{codett|2=cobolfree|USE «AFTER» EC}} ''exception-name'' «FILE ''file-name»''.</code>
| {{n/a}}
|-
| [[Rust (programming language)|Rust]]
| colspan=2 {{No}}<ref>{{cite book |last1=Klabnik |first1=Steve |last2=Nichols |first2=Carol |title=The Rust Programming Language |url=https://doc.rust-lang.org/book/title-page.html |chapter=Error Handling|chapter-url=https://doc.rust-lang.org/book/ch09-00-error-handling.html}}</ref>
| <code>assert!(''condition'')</code>
|}
 
* {{note|common lisp restarts|a}} Common Lisp allows <code>with-simple-restart</code>, <code>restart-case</code> and <code>restart-bind</code> to define restarts for use with <code>invoke-restart</code>. Unhandled conditions may cause the implementation to show a restarts menu to the user before unwinding the stack.
== Function declaration ==
* {{note|Ada uncaught exceptions|b}} Uncaught exceptions are propagated to the innermost dynamically enclosing execution. Exceptions are not propagated across tasks (unless these tasks are currently synchronised in a rendezvous).
{| class="wikitable"
 
=== Other control flow statements ===
{| class="wikitable sortable"
|-
!
! exit block (break)
! basic
! continue
! value-returning function
! [[Label (programming language)|label]]
! branch ([[goto]])
! return value from generator
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| C
| <code>exit ''«loop_name»'' «when ''condition»''</code>
| void foo(parameters) { }
| {{n/a}}
| ''type'' foo(parameters) { }
| <code>''label'':</code>
| <code>goto ''label''</code>
| {{n/a}}
|-
| [[ALGOL 68]]
| C++ (STL)
| <code>''value'' exit;</code> ...
| as above
| <code>do ''statements;'' skip exit; ''label: statements'' od</code>
| as above
| <code>label:</code> ...
| <code>go to ''label; ...''<br/>goto ''label; ...<br/>label; ...''</code>
| <code>yield(value)</code>
([[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>
|-
| [[APL (programming language)|APL]]
| Java
| <code>:Leave</code>
| public or private + as above
| <code>:Continue</code>
| public or private +as above
| <code>''label'':</code>
| <code>→''label''</code><br/>or<br/><code>:GoTo ''label''</code>
| {{n/a}}
|-
| [[C (programming language)|C]] ([[C99]])
| Pascal
| rowspan=5| <code>break;</code>
| procedure foo(...);
| rowspan=5| <code>continue;</code>
| function foo(...):type;
| rowspan=12| <code>''label'':</code>
| rowspan=5| <code>goto ''label'';</code>
| rowspan=4 {{n/a}}
|-
| [[Objective-C]]
| Visual Basic
| Sub foo(parameters)
| Function foo(parameters) As ''type''
|-
| [[C++]] (STL)
| Python
| def foo(parameters): \n \t ''instructions'' \n
| add ''return value'' at the end.
|-
| [[S-Lang_D (programming_languageprogramming language)|S-LangD]]
|-
| define foo (parameters ; qualifiers) { }
| [[C Sharp (programming language)|C#]]
| define foo (parameters ; qualifiers) { ... return ''value''; }
| <code>yield return ''value'';</code>
|-
| [[Java (programming language)|Java]]
| rowspan=2| <code>break ''«label»'';</code>
| rowspan=2| <code>continue ''«label»'';</code>
| rowspan=2 {{n/a}}
|
|-
| [[JavaScript]]
| <code>yield ''value«;»''</code>
|-
| [[PHP]]
| <code>break ''«levels»'';</code>
| <code>continue ''«levels»'';</code>
| rowspan=3| <code>goto ''label'';</code>
| <code>yield ''«key <nowiki>=></nowiki>» value;''</code>
|-
| [[Perl]]
| rowspan=2| <code>last ''«label»'';</code>
| rowspan=2| <code>next ''«label»'';</code>
|
|-
| [[Raku (programming language)|Raku]]
|
|-
| [[Go (programming language)|Go]]
| <code>break ''«label»''</code>
| <code>continue ''«label»''</code>
| <code>goto ''label''</code>
|
|-
| [[Swift (programming language)|Swift]]
| <code>break ''«label»''</code>
| <code>continue ''«label»''</code>
| {{n/a}}
|
|-
| [[Bash shell]]
| <code>break ''«levels»''</code>
| <code>continue ''«levels»''</code>
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Common Lisp]]
| <code>(return)</code><br/>or<br/><code>(return-from ''block'')</code><br/>or<br/><code>(loop-finish)</code>
|
| <code>(tagbody ''tag''{{indent|2}}''...''{{indent|2}}''tag''<br/>''...'')</code>
| <code>(go ''tag'')</code>
|
|-
| [[Scheme (programming language)|Scheme]]
|
|
|
|
|
|-
| [[ISLISP]]
| <code>(return-from ''block'')</code>
|
| <code>(tagbody ''tag''{{indent|2}}''...''{{indent|2}}''tag''<br/>''...'')</code>
| <code>(go ''tag'')</code>
|
|-
| Pascal (ISO)
| colspan=2 {{n/a}}
| rowspan=2| <code>''label'':</code>{{ref|Pascal's declarations|[a]}}
| rowspan=2| <code>goto ''label'';</code>
| rowspan=4 {{n/a}}
|-
| [[Pascal (programming language)|Pascal]] ([[Free Pascal|FPC]])
| <code>break;</code>
| <code>continue;</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=3| <code>Exit ''block''</code>Alternatively, for methods,<br/><code>Return</code>
| {{n/a}}
| rowspan=3| <code>''label'':</code>
| rowspan=3| <code>GoTo ''label''</code>
|-
| [[Xojo]]
| rowspan=2 |<code>Continue ''block''</code>
|-
| [[Visual Basic .NET]]
| <code>Yield ''value''</code>
|-
| [[Python (programming language)|Python]]
| <code>break</code>
| <code>continue</code>
| colspan=2 {{n/a}}
| <code>yield ''value''</code>
|-
| [[RPG IV]]
| <code>LEAVE;</code>
| <code>ITER;</code>
|
|
|
|-
| [[S-Lang]]
| <code>break;</code>
| <code>continue;</code>
|
|
|
|-
| [[Fortran]]
| <code>EXIT</code>
| <code>CYCLE</code>
| <code>label</code>{{ref|Fortran label|[b]}}
| <code>GOTO ''label''</code>
| {{n/a}}
|-
| [[Ruby (programming language)|Ruby]]
| <code>break</code>
| <code>next</code>
|
|
|
|-
| [[Windows PowerShell]]
| <code>break ''«label»''</code>
| <code>continue</code>
|
|
|
|-
| [[OCaml]]
| rowspan=4 colspan=4 {{n/a}}
|
|-
| [[F Sharp (programming language)|F#]]
|
|-
| [[Standard ML]]
|
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
|
|-
| [[COBOL]]
| <code>EXIT&nbsp;PERFORM</code> or <code>EXIT&nbsp;PARAGRAPH</code> or <code>EXIT&nbsp;SECTION</code> or <code>EXIT.</code>
| <code>EXIT PERFORM CYCLE</code>
| <code>''label'' «SECTION».</code>
| <code>GO TO ''label''</code>
| {{n/a}}
|}
* {{note|Pascal's declarations|a}} Pascal has declaration blocks. See [[#Functions|functions]].
* {{note|Fortran label|b}} label must be a number between 1 and 99999.
 
== [[Subroutine|Function]]s ==
== Data conversions ==
See ''[[reflective programming]]'' for calling and declaring functions by strings.
{{sort-under}}
{| class="wikitable sortable sort-under"
|- valign="top"
!
! calling a function
! basic/void function
! value-returning function
! required [[main function]]
|- valign="top"
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| <code>''foo «(parameters)»''</code>
| <code>procedure ''foo «(parameters)»'' is begin ''statements'' end ''foo''</code>
| <code>function ''foo «(parameters)»'' return ''type'' is begin ''statements'' end ''foo''</code>
| {{n/a}}
|- valign="top"
| [[ALGOL 68]]
| <code>''foo «(parameters)»'';</code>
| <code>proc ''foo'' = ''«(parameters)»'' [[void type|void]]: ( ''instructions'' );</code>
| <code>proc ''foo'' = ''«(parameters)»'' rettype: ( ''instructions ...; retvalue'' );</code>
| {{n/a}}
|- valign="top"
| [[APL (programming language)|APL]]
| <code>''«parameters»'' foo ''parameters''</code>
| <code>''foo←''{ ''statements'' }</code>
| <code>''foo←''{ ''statements'' }</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/>{{codett|2=c|int main(«int argc, char *argv[]»)}} { {{indent|2}}''instructions''<br/>}</code>
|- valign="top"
| [[Objective-C]]
|- valign="top"
| [[C++]] (STL)
|- valign="top"
| [[Java (programming language)|Java]]
| <code>{{codett|2=java|public static void main(String[] args)}} { ''instructions'' }</code><br/>or<br/><code>{{codett|2=java|public static void main(String}}[[variadic function|...]] args) { ''instructions'' }</code>
|- valign="top"
| [[D (programming language)|D]]
| <code>{{codett|2=d|int main(«char[][] args»)}} { ''instructions''}</code><br/>or<br/><code>{{codett|2=d|int main(«string[] args»)}} { ''instructions''}</code><br/>or<br/><code>{{codett|2=d|void main(«char[][] args»)}} { ''instructions''}</code><br/>or<br/><code>{{codett|2=d|void main(«string[] args»)}} { ''instructions''}</code>
|- valign="top"
| [[C Sharp (programming language)|C#]]
| Same as above; alternatively, if only one statement:
<code>[[void type|void]] foo(''«parameters»'') => ''statement'';</code>
| Same as above; alternatively, if simple enough to be an expression:
<code>[[void type|void]] foo(''«parameters»'') => ''expression'';</code>
| {{code|2=c#|static void Main(«string[] args») method_body}}<br/>May instead return <code>int</code>.<br/>(starting with C# 7.1:) May return <code>Task</code> or {{code|2=c#|Task<int>}}, and if so, may be <code>async</code>.
|- valign="top"
| [[JavaScript]]
| <code>function foo(''«parameters»'') { ''instructions'' }</code><br/>or<br/><code>{{codett|2=javascript|1=var foo = function (}}''«parameters»'') { ''instructions'' }</code><br/>or<br/><code>{{codett|2=javascript|1=var foo = new Function (}}''"«parameter»"'', ''...'', ''"«last parameter»"'' "''instructions''");</code>
| <code>function foo(''«parameters»'') { ''instructions ...'' return ''value''; }</code>
| {{n/a}}
|- valign="top"
| [[Go (programming language)|Go]]
| <code>func foo(''«parameters»'') { ''instructions'' }</code>
| <code>func foo(''«parameters»'') ''type'' { ''instructions ...'' return ''value'' }</code>
| <code>func main() { ''instructions'' }</code>
|- valign="top"
| [[Swift (programming language)|Swift]]
| <code>func foo(''«parameters»'') { ''instructions'' }</code>
| <code>func foo(''«parameters»'') -> ''type'' { ''instructions ...'' return ''value'' }</code>
| {{n/a}}
|- valign="top"
| [[Common Lisp]]
| rowspan=3| <code>(foo ''«parameters»'')</code>
| <code>([[defun]] foo (''«parameters»''){{indent|2}}''instructions'')</code><br/>or<br/><code>{{codett|2=lisp|1=(setf (symbol-function '}}''symbol''){{indent|2}}''function'')</code>
| <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/>or<br/><code>(define foo ([[anonymous function|lambda]] (''parameters'') ''instructions''))</code>
| <code>(define (foo ''parameters'') ''instructions... return_value'')</code><br/>or<br/><code>(define foo ([[anonymous function|lambda]] (''parameters'') ''instructions... return_value''))</code>
|- valign="top"
| [[ISLISP]]
| <code>([[defun]] foo (''«parameters»''){{indent|2}}''instructions'')</code>
| <code>([[defun]] foo (''«parameters»''){{indent|2}}''...{{indent|2}}value'')</code>
|- valign="top"
| [[Pascal (programming language)|Pascal]]
| <code>foo«(''parameters'')»</code>
| <code>procedure foo«(''parameters'')»; «forward;»{{ref|forward declaration|[a]}}<br/>«label{{indent|2}}''label declarations''»<br/>«const{{indent|2}}''constant declarations''»<br/>«type{{indent|2}}''type declarations''»<br/>«var{{indent|2}}''variable declarations»<br/>«local function declarations»''<br/>begin{{indent|2}}''instructions''<br/>end;</code>
| <code>function foo«(''parameters'')»: ''type''; «forward;»{{ref|forward declaration|[a]}}<br/>«label{{indent|2}}''label declarations''»<br/>«const{{indent|2}}''constant declarations''»<br/>«type{{indent|2}}''type declarations''»<br/>«var{{indent|2}}''variable declarations»<br/>«local function declarations»''<br/>begin{{indent|2}}''instructions'';{{indent|2}}foo := ''value''<br/>end;</code>
| <code>program ''name'';<br/>«label{{indent|2}}''label declarations''»<br/>«const{{indent|2}}''constant declarations''»<br/>«type{{indent|2}}''type declarations''»<br/>«var{{indent|2}}''variable declarations»<br/>«function declarations»''<br/>begin{{indent|2}}''instructions''<br/>end.</code> <!-- somewhat of a technicality -->
|- valign="top"
| [[Visual Basic (classic)|Visual Basic]]
| rowspan=3| <code>Foo(''«parameters»'')</code>
| rowspan=3| <code>Sub Foo«(''parameters'')»{{indent|2}}''instructions''<br/>End Sub</code>
| <code>Function Foo«(''parameters'')»« As'' type»''{{indent|2}}''instructions''{{indent|2}}Foo = ''value''<br/>End Function</code>
| <code>Sub Main(){{indent|2}}''instructions''<br/>End Sub</code>
|- 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/>End Function</code><br/>The <code>As</code> clause is not required if <code>Option Strict</code> is off. A type character may be used instead of the <code>As</code> clause.<br/>If control exits the function without a return value having been explicitly specified, the function returns the default value for the return type.
| rowspan=2| <code>{{codett|2=vbnet|Sub Main(««ByVal »args() As String»)}}{{indent|2}}''instructions''<br/>End Sub</code>or<br/><code>{{codett|2=vbnet|Function Main(««ByVal »args() As String») As Integer}}{{indent|2}}''instructions''<br/>End Function</code>
|- valign="top"
| [[Xojo]]
|- valign="top"
| [[Python (programming language)|Python]]
| <code>foo(''«parameters»'')</code>
| <code>def foo(''«parameters»''):<br/>{{keypress|Tab}}''instructions''</code>
| <code>def foo(''«parameters»''):<br/>{{keypress|Tab}}''instructions''<br/>{{keypress|Tab}}return ''value''</code>
| {{n/a}}
|- valign="top"
| [[S-Lang]]
| <code>foo(''«parameters» «;qualifiers»'')</code>
| <code>define foo (''«parameters»'') { ''instructions'' }</code>
| <code>define foo (''«parameters»'') { ''instructions ...'' return ''value''; }</code>
| <code>public define slsh_main () { ''instructions'' }</code>
|- valign="top"
| [[Fortran]]
| <code>foo (''«arguments»'')<br/>CALL sub_foo (''«arguments»'')</code>{{ref|Fortran arguments|[c]}}
| <code>SUBROUTINE sub_foo (''«arguments»''){{indent|2}}''instructions<br/>''END SUBROUTINE</code>{{ref|Fortran arguments|[c]}}
| <code>''type'' FUNCTION foo (''«arguments»''){{indent|2}}''instructions''{{indent|2}}''...''{{indent|2}}''foo'' = ''value''<br/>END FUNCTION</code>{{ref|Fortran arguments|[c]}}
| <code>PROGRAM ''main''{{indent|2}}''instructions''<br/>END PROGRAM</code>
|- valign="top"
| [[Forth (programming language)|Forth]]
| <code>''«parameters» ''FOO</code>
| <code>{{codett|2=forth|: FOO « stack effect comment:}} ('' before'' -- ) »{{indent|2}}''instructions''<br/>;</code>
| <code>{{codett|2=forth|: FOO « stack effect comment:}} ('' before'' -- ''after'' ) »{{indent|2}}''instructions''<br/>;</code>
| {{n/a}}
|- valign="top"
| [[PHP]]
| <code>foo(''«parameters»'')</code>
| <code>function foo(''«parameters»'') { ''instructions'' }</code>
| <code>function foo(''«parameters»'') { ''instructions'' ... return ''value''; }</code>
| rowspan=4 {{n/a}}
|- valign="top"
| [[Perl]]
| <code>foo(''«parameters»'')</code><br/>or<br/><code>&foo«(''parameters'')»</code>
| <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/>or<br/><code>&foo«(''parameters'')»</code>
| <code>{{codett|2=raku|«multi »sub foo(}}''parameters'') { ''instructions'' }</code>
| <code>«our «''type''» »{{codett|2=raku|«multi »sub foo(}}''parameters'') { ''instructions ...'' «return» ''value''; }</code>
|- valign="top"
| [[Ruby (programming language)|Ruby]]
| <code>foo«(''parameters'')»</code>
| <code>def foo«(''parameters'')»{{indent|2}}''instructions''<br/>end</code>
| <code>def foo«(''parameters'')»{{indent|2}}''instructions''{{indent|2}}«return» ''value''<br/>end</code>
|- valign="top"
| [[Rust (programming language)|Rust]]
| <code>foo(''«parameters»'')</code>
| <code>fn foo(''«parameters»'') { ''instructions'' }</code>
| <code>fn foo(''«parameters»'') -> ''type'' { ''instructions'' }</code>
| <code>fn main() { ''instructions'' }</code>
|- valign="top"
| [[Scala (programming language)|Scala]]
| <code>''foo''«(''parameters'')»</code>
| <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/>or<br/><code>function ''foo'' { «param(''parameters'')» ''instructions'' }</code>
| <code>function ''foo'' «(''parameters'')» { ''instructions ...'' return ''value'' };</code><br/>or<br/><code>function foo { «param(''parameters'')» ''instructions ...'' return ''value'' }</code>
| rowspan=4 {{n/a}}
|- valign="top"
| rowspan=2| [[Bash shell]]
| rowspan=2| <code>foo ''«parameters»''</code>
| <code>function foo {{{indent|2}}''instructions''<br/>}</code><br/>or<br/><code>foo () {{{indent|2}}''instructions''<br/>}</code>
| <code>function foo {{{indent|2}}''instructions''{{indent|2}}return ''«exit_code»''<br/>}</code><br/>or<br/><code>foo () { {{indent|2}}''instructions''{{indent|2}}return ''«exit_code»''<br/>}</code>
|- valign="top"
| colspan=2|
 
* parameters
{| class="wikitable"
** <code>$''n''</code> (''$1'', ''$2'', ''$3'', ...)
** <code>$@</code> (all parameters)
** <code>$#</code> (the number of parameters)
** <code>$0</code> (this function name)
|- valign="top"
| [[OCaml]]
| rowspan=4| <code>foo ''parameters''</code>
| rowspan=2| <code>let «rec» foo ''parameters'' = ''instructions''</code>
| rowspan=2| <code>let «rec» foo ''parameters'' = ''instructions... return_value''</code>
|- valign="top"
| [[F Sharp (programming language)|F#]]
| <code>{{codett|2=f#|[<EntryPoint>] let main args}} ='' instructions''</code>
|- valign="top"
| [[Standard ML]]
| <code>fun foo ''parameters'' = ( ''instructions'' )</code>
| <code>fun foo ''parameters'' = ( ''instructions... return_value'' )</code>
|
|- valign="top"
| [[Haskell]]
| <code>foo ''parameters'' = do<br/>{{keypress|Tab}}''instructions''</code>
| <code>foo ''parameters'' = ''return_value''</code><br/>or<br/><code>foo ''parameters'' = do<br/>{{keypress|Tab}}''instructions''<br/>{{keypress|Tab}}return ''value''</code>
| <code>«main :: IO ()»<br/>main = do ''instructions''</code>
|- valign="top"
| [[Eiffel (programming language)|Eiffel]]
| <code>foo (''«parameters»'')</code>
| <code>foo (''«parameters»''){{indent|2}}require{{indent|4}}''preconditions''{{indent|2}}do{{indent|4}}''instructions''{{indent|2}}ensure{{indent|4}}''postconditions''{{indent|2}}end</code>
| <code>foo (''«parameters»'')'': type''{{indent|2}}require{{indent|4}}''preconditions''{{indent|2}}do{{indent|4}}''instructions''{{indent|4}}Result '':= value''{{indent|2}}ensure{{indent|4}}''postconditions''{{indent|2}}end</code>
| {{ref|root class and feature|[b]}}
|- valign="top"
| rowspan=2| [[CoffeeScript]]
| <code>foo()</code>
| {{code|2=coffeescript|1=foo = ->}}
| <code>{{codett|2=coffeescript|1=foo = ->}} ''value''</code>
| rowspan=2 {{n/a}}
|- valign="top"
| <code>foo ''parameters''</code>
| {{code|2=coffeescript|1=foo = () ->}}
| <code>foo = ( ''parameters'' ) <nowiki>-></nowiki> ''value''</code>
|- valign="top"
| rowspan=2 | [[COBOL]]
| <code>CALL "''foo''" «USING ''parameters»{{indent|2}}«exception-handling»<br/>«''END-CALL''»''</code>{{ref|COBOL calling programs|[d]}}
| <code>«IDENTIFICATION DIVISION.»<br/>PROGRAM-ID. ''foo''.''<br/>«other divisions...»<br/>''PROCEDURE DIVISION ''«''USING ''parameters»''.''{{indent|2}}instructions''.</code>
| rowspan=2 | <code>«IDENTIFICATION DIVISION.»<br/>PROGRAM-ID/FUNCTION-ID. ''foo''.<br/>«''other divisions...''»<br/>DATA DIVISION.<br/>«''other sections...''»<br/>LINKAGE SECTION.<br/>«''parameter definitions...''»<br/>''variable-to-return definition''<br/>«''other sections...''»<br/>PROCEDURE DIVISION «USING ''parameters»'' RETURNING ''variable-to-return''.{{indent|2}}''instructions''.</code>
| rowspan=2 {{n/a}}
|-
| <code>«FUNCTION» ''foo«(«parameters»)»''</code>
!
| {{n/a}}
|}
 
* {{note|forward declaration|a}} Pascal requires "<code>forward;</code>" for [[forward declaration]]s.
* {{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 <code>PARAMETER</code> is a language keyword); the <code>CALL</code> keyword is required for subroutines.
* {{note|COBOL calling programs|d}} Instead of using <code>"foo"</code>, a string variable may be used instead containing the same value.
 
== [[Type conversion]]s{{anchor|Data conversions}} ==
Where ''string'' is a signed decimal number:
{| class="wikitable sortable sort-under"
|-
!
! string to integer
! string to floatlong integer
! string to floating point
! integer to string
! floatfloating point to string
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| C
| <code>Integer'Value (''string_expression'')</code>
| ''integer'' = atoi(''string'');
| <code>Long_Integer'Value (''string_expression'')</code>
| ''float'' = atof(''string'');
| <code>Float'Value (''string_expression'')</code>
| sprintf(''string'', "%i", ''integer'');
| <code>Integer'Image (''integer_expression'')</code>
| sprintf(''string'', "%f", ''float'');
| <code>Float'Image (''float_expression'')</code>
|-
| rowspan=3 | [[ALGOL 68]] with general, and then specific formats
| C++
| colspan=5 align=center| With prior declarations and association of: <code>string ''buf := "12345678.9012e34 ";'' file ''proxy; associate(proxy, buf);''</code>
|
| -
| <code>get(proxy, ivar);</code>
| <code>get(proxy, livar);</code>
| <code>get(proxy, rvar);</code>
| <code>put(proxy, ival);</code>
| <code>put(proxy, rval);</code>
|-
| <code>getf(proxy, ($g$, ivar));</code><br/>or<br/><code>getf(proxy, ($dddd$, ivar));</code>
| <code>getf(proxy, ($g$, livar));</code><br/>or<br/><code>getf(proxy, ($8d$, livar));</code>
| <code>getf(proxy, ($g$, rvar));</code><br/>or<br/><code>getf(proxy, ($8d.4dE2d$, rvar));</code>
| <code>putf(proxy, ($g$, ival));</code><br/>or<br/><code>putf(proxy, ($4d$, ival));</code>
| <code>putf(proxy, ($g(width, places, exp)$, rval));</code><br/>or<br/><code>putf(proxy, ($8d.4dE2d$, rval));</code>
|-
| [[APL (programming language)|APL]]
| <code>⍎''string_expression''</code>
| <code>⍎''string_expression''</code>
| <code>⍎''string_expression''</code>
| <code>⍕''integer_expression''</code>
| <code>⍕''float_expression''</code>
|-
| [[C (programming language)|C]] ([[C99]])
| <code>''integer'' = [[atoi]](''string'');</code>
| <code>''long'' = [[atol (programming)|atol]](''string'');</code>
| <code>''float'' = [[atof]](''string'');</code>
| <code>[[sprintf]](''string'', "%i", ''integer'');</code>
| <code>[[sprintf]](''string'', "%f", ''float'');</code>
|-
| [[Objective-C]]
| <code>''integer'' = [''string'' intValue];</code>
| <code>''long'' = [''string'' longLongValue];</code>
| <code>''float'' = [''string'' doubleValue];</code>
| <code>''string'' = {{codett|2=objc|[NSString stringWithFormat:@"%i",}} ''integer''];</code>
| <code>''string'' = {{codett|2=objc|[NSString stringWithFormat:@"%f",}} ''float''];</code>
|-
| [[C++]] (STL)
| colspan=3| <code>«std::»istringstream(''string'') >> ''number;''</code>
| colspan=2| <code>«std::»ostringstream ''o''; ''o'' << ''number''; ''string'' = ''o''.str();</code>
|-
| [[C++11]]
| <code>''integer'' = «''std::''»stoi(''string'');</code>
| <code>''long'' = «''std::''»stol(''string'');</code>
| <code>''float'' = «''std::''»stof(''string); double'' = «''std::''»stod(''string'');</code>
| colspan=2| <code>''string'' = «''std::''»to_string(''number'');</code>
|-
| [[C Sharp (programming language)|C#]]
| <code>''integer'' = int.Parse<wbr/>(''string'');</code>
| <code>''long'' = long.Parse<wbr/>(''string'');</code>
| <code>''float'' = float.Parse<wbr/>(''string'');</code><code>''double'' = double.Parse<wbr />(''string'');</code>
| colspan=2| <code>''string'' = ''number''<wbr/>.ToString();</code>
|-
| [[D (programming language)|D]]
| <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/><code>''double'' = std.conv.to!double<wbr />(''string'')</code>
| colspan=2| <code>''string'' = std.conv.to!string<wbr/>(''number'')</code>
|-
| [[Java (programming language)|Java]]
| <code>''integer'' = Integer.parseInt<wbr/>(''string'');</code>
| <code>''long'' = Long.parseLong<wbr/>(''string'');</code>
| <code>''float'' = Float.parseFloat<wbr/>(''string'');</code><br/><code>''double'' = Double.parseDouble<wbr/>(''string'');</code>
| <code>''string'' = Integer.toString<wbr/>(''integer'');</code><br/><code>''string'' = String.valueOf<wbr />(''integer'');</code>
| <code>''string'' = Float.toString<wbr/>(''float'');</code><br/><code>''string'' = Double.toString<wbr />(''double'');</code>
|-
| [[JavaScript]]{{ref|JavaScript's technicalities|[a]}}
| colspan=2| <code>''integer'' = parseInt(''string'');</code>
| <code>''float'' = parseFloat(''string'');</code><br/><code>''float'' = new Number (''string'');</code><br/><code>''float'' = Number (''string'');</code><br/><code>''float'' = +''string;''</code>
| colspan=2| <code>''string'' = ''number''.toString ();</code><br/><code>''string'' = String (''number'');</code><br/><code>''string'' = ''number''+"";</code><br/><code>''string'' = `${''number''}`</code>
|-
| [[Go (programming language)|Go]]
| <code>''integer'', ''error'' = strconv.Atoi(''string'')<br/>''integer'', ''error'' = strconv.ParseInt<wbr/>(''string'', 10, 0)</code>
| <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.FormatInt<wbr />(''integer'', 10)</code><br/><code>''string'' = fmt.Sprint(''integer'')</code>
| <code>''string'' = strconv.FormatFloat<wbr/>(''float'')</code><br/><code>''string'' = fmt.Sprint<wbr />(''float'')</code>
|-
| [[Rust (programming language)|Rust]]{{ref|Rust type conversion|[d]}}
| <code>''string''.parse::<i32>()</code><br/><code>i32::from_str(''string'')</code>
| <code>''string''.parse::<i64>()</code><br/><code>i64::from_str(''string'')</code>
| <code>''string''.parse::<f64>()</code><br/><code>f64::from_str(''string'')</code>
| <code>''integer''.to_string()</code>
| <code>''float''.to_string()</code>
|-
| [[Common Lisp]]
| colspan=2| <code>(setf ''integer'' (parse-integer ''string''))</code>
| <code>(setf ''float'' (read-from-string ''string''))</code>
| colspan=2| <code>(setf ''string'' (princ-to-string ''number''))</code>
|-
| [[Scheme (programming language)|Scheme]]
| colspan=3| <code>(define ''number'' (string->number ''string''))</code>
| colspan=2| <code>(define ''string'' (number->string ''number''))</code>
|-
| [[ISLISP]]
| colspan=2| <code>(setf ''integer'' (convert ''string'' &lt;integer&gt;))</code>
| <code>(setf ''float'' (convert ''string'' &lt;float&gt;))</code>
| colspan=2| <code>(setf ''string'' (convert ''number'' &lt;string&gt;))</code>
|-
| Pascal <!-- Pascal or Delphi? -->
| <code>''integer'' := StrToInt(''string'');</code>
|
| <code>''float'' := StrToFloat(''string'');</code>
| <code>''string'' := IntToStr(''integer'');</code>
| <code>''string'' := FloatToStr(''float'');</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| <code>''integer'' = CInt(''string'')</code>
| <code>''long'' = CLng(''string'')</code>
| <code>''float'' = CSng(''string'')<br/>''double'' = CDbl(''string'')</code>
| <code>''string'' = CStr(''number'')</code>
|
|-
| [[Visual Basic .NET]]<br/>(can use both VB syntax above and .NET methods shown right)
| Java
| <code>''integer'' = Integer.parseIntParse<wbr />(''string'');</code>
| <code>''floatlong'' = FloatLong.parseIntParse<wbr />(''string'');</code>
| <code>''float'' = Single.Parse<wbr />(''string'')</code><br/><code>''double'' = Double.Parse<wbr />(''string'')</code>
| ''string'' = ''integer'';
| colspan="2" | <code>''string'' = ''float number'';<wbr />.ToString()</code>
|-
| [[Xojo]]
| Pascal
| <code>''integer'' := StrToIntVal(''string'');</code>
| <code>''floatlong'' := StrToFloatVal(''string'');</code>
| <code>''double'' = Val(''string'')</code><br/><code>''double'' := IntToStrCDbl(''integerstring'');</code>
| colspan=2| <code>''string'' = CStr(''number'')</code><br/>or<br/><code>''string'' = Str(''number'')</code>
| ''string'' := FloatToStr(''float'');
|-
| [[Python (programming language)|Python]]
| Visual Basic
| CInt<code>''integer'' = int(''string'')</code>
| CSng(<code>''stringlong'') ''or''= CDbllong(''string'')</code>
| <code>''float'' = float(''string'')</code>
| CStr(''integer'')
| colspan=2| <code>''string'' = str(''number'')</code>
| CStr(''float'')
|-
| [[S-Lang]]
| Python
| <code>''integer'' = [[atoi]](''string'');</code>
| int('5')
| <code>''long'' = [[atol (programming)|atol]](''string'');</code>
| float('5.0')
| <code>''float'' = [[atof]](''string'');</code>
| str(5)
| colspan=2| <code>''string'' = string(''number'');</code>
| str(5.0)
|-
| [[Fortran]]
| colspan=3| <code>READ(''string'',''format'') ''number''</code>
| colspan=2| <code>WRITE(''string'',''format'') ''number''</code>
|-
| [[PHP]]
| colspan=2| <code>''integer'' = intval(''string'');</code><br/>or<br/><code>''integer'' = (int)''string'';</code>
| <code>''float'' = floatval(''string'');</code><br/><code>''float'' = (float)''string'';</code>
| colspan=2| <code>''string'' = "''$number''";</code><br/>or<br/><code>''string'' = strval(''number'');</code><br/>or<br/><code>''string'' = (string)''number'';</code>
|-
| [[Perl]]{{ref|Perl's technicalities|[b]}}
| colspan=3| <code>''number'' = 0 + ''string;''</code>
| colspan=2| <code>''string'' = "''number''";</code>
|-
| [[Raku (programming language)|Raku]]
| colspan=3| <code>''number'' = +''string;''</code>
| colspan=2| <code>''string'' = ~''number'';</code>
|-
| [[Ruby (programming language)|Ruby]]
| colspan=2| <code>''integer'' = ''string''.to_i</code><br/>or<br/><code>''integer'' = Integer(''string'')</code>
| <code>''float'' = ''string''.to_f</code><br/><code>''float'' = Float(''string'')</code>
| colspan=2| <code>''string'' = ''number''.to_s</code>
|-
| [[Scala (programming language)|Scala]]
| <code>''integer'' = ''string''.toInt</code>
| <code>''long'' = ''string''.toLong</code>
| <code>''float'' = ''string''.toFloat</code><code>''double'' = ''string''.toDouble</code>
| colspan=2| <code>''string'' = ''number''.toString</code>
|-
| [[Smalltalk]]
| colspan=2| <code>''integer := Integer'' readFrom: ''string''</code>
| <code>''float := Float'' readFrom: ''string''</code>
| colspan=2| <code>''string := number ''asString</code>
|-
| [[Windows PowerShell]]
| <code>''integer'' = [int]''string''</code>
| <code>''long'' = [long]''string''</code>
| <code>''float'' = [float]''string''</code>
| colspan=2| <code>''string'' = [string]''number'';</code><br/>or<br/><code>''string'' = "''number''";</code><br/>or<br/><code>''string'' = (''number'').ToString()</code>
|-
| [[OCaml]]
| <code>let ''integer'' = int_<wbr/>of_string ''string''</code>
|
| <code>let ''float'' = float_<wbr/>of_string ''string''</code>
| <code>let ''string'' = string_<wbr/>of_int ''integer''</code>
| <code>let ''string'' = string_<wbr/>of_float ''float''</code>
|-
| [[F Sharp (programming language)|F#]]
| <code>let ''integer'' = int ''string''</code>
| <code>let ''integer'' = int64 ''string''</code>
| <code>let ''float'' = float ''string''</code>
| colspan=2| <code>let ''string'' = string ''number''</code>
|-
| [[Standard ML]]
| <code>val ''integer'' = Int<wbr/>.fromString ''string''</code>
|
| <code>val ''float'' = Real<wbr/>.fromString ''string''</code>
| <code>val ''string'' = Int<wbr/>.toString ''integer''</code>
| <code>val ''string'' = Real<wbr/>.toString ''float''</code>
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| 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>
|-
| [[S-Lang_(programming_language)|S-Lang]]
| ''integer'' = atoi(''string'');
| ''float'' = atof(''string'');
| ''string'' = string(''integer'');
| ''string'' = string(''float'');
|}
 
* {{note|JavaScript's technicalities|a}} JavaScript only uses floating point numbers so there are some technicalities.<ref name="Javascript numbers" />
== Standard Input and Standard Output ==
* {{note|Perl's technicalities|b}} Perl doesn't have separate types. Strings and numbers are interchangeable.
* {{note|COBOL's NUMVAL alternatives|c}} <code>NUMVAL-C</code> or <code>NUMVAL-F</code> may be used instead of <code>NUMVAL</code>.
* {{note|Rust type conversion}} [https://doc.rust-lang.org/stable/std/primitive.str.html#method.parse <code>str::parse</code>] is available to convert any type that has an implementation of the [https://doc.rust-lang.org/stable/std/str/trait.FromStr.html <code>std::str::FromStr</code>] trait. Both <code>str::parse</code> and [https://doc.rust-lang.org/stable/std/str/trait.FromStr.html#tymethod.from_str <code>FromStr::from_str</code>] return a [[result type|<code>Result</code>]] that contains the specified type if there is no error. The [[turbofish]] (<code><nowiki>::<_></nowiki></code>) on <code>str::parse</code> can be omitted if the type can be inferred from context.
 
== [[Standard streams|Standard stream I/O]] ==
{| class="wikitable"
{| class="wikitable sortable"
|-
! rowspan=2|
! read from
! colspan=2| write to
|-
!
! [[stdin]]
! [[stdout]]
! [[stderr]]
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| C
| <code>Get (''x'')</code>
| scanf( ... ); <br> fscanf(stdin, ... );
| <code>Put (''x'')</code>
| printf( ... ); <br> fprintf(stdout, ... );
| <code>Put (Standard_Error, ''x'')</code>
| fprintf(stderr, ... );
|-
| [[ALGOL 68]]
| C++
| <code>readf((''$format$'', ''x''));</code><br/>or<br/><code>getf(stand in, (''$format$'', ''x''));</code>
| cin >> ''x'';
| <code>[[printf]]((''$format$'', ''x''));</code><br/>or<br/><code>putf(stand out, (''$format$'', ''x''));</code>
| cout << ''x'';
| <code>putf(stand error, (''$format$'', ''x''));</code>{{ref|ALGOL Unformatted|[a]}}
| cerr << ''x'';
|-
| [[APL (programming language)|APL]]
| Java
| <code>''x←''⎕</code>
| ''x'' = System.in.read();
| System.out.print(<code>⎕←''x'');</code>
| System.err.print(<code>⍞←''x'');</code>
|-
| [[C (programming language)|C]] ([[C99]])
| Pascal
| <code>[[scanf]](''format'', &''x'');</code><br/>or<br/><code>[[fscanf]](stdin, ''format'', &''x'');</code>{{ref|more c input|[b]}}
| read( ... ); <br> readln( ... );
| <code>[[printf]](''format'', ''x'');</code><br/>or<br/><code>[[fprintf]](stdout, ''format'', ''x'');</code>{{ref|more c output|[c]}}
| write( ... ); <br> writeln( ... );
| <code>[[fprintf]](stderr, ''format'', ''x'');</code>{{ref|more c error output|[d]}}
| var IOResult;
|-
| [[Objective-C]]
| Visual Basic
| <syntaxhighlight lang="objc" inline>data = [[NSFileHandle fileHandleWithStandardInput] readDataToEndOfFile];</syntaxhighlight>
| input
| <syntaxhighlight lang="objc" inline>[[NSFileHandle fileHandleWithStandardOutput] writeData:data];</syntaxhighlight>
| print ''x''
| <syntaxhighlight lang="objc" inline>[[NSFileHandle fileHandleWithStandardError] writeData:data];</syntaxhighlight>
| ?
|-
| Python[[C++]]
| <code>[[iostream|«std::»cin]] >> ''x'';</code><br/>or<br/><code>«std::»getline(«std::»cin, ''str'');</code>
| <code>[[iostream|«std::»cout]] << ''x'';</code>
| <code>[[iostream|«std::»cerr]] << ''x'';</code><br/>or<br/><code>[[iostream|«std::»clog]] << ''x'';</code>
|-
| [[C Sharp (programming language)|C#]]
| <code>''x'' = Console.Read();</code><br/>or<br/><code>''x'' = Console.ReadLine();</code>
| <code>Console.Write(''«format'', »''x'');</code><br/>or<br/><code>Console.WriteLine(''«format'', »''x'');</code>
| <code>Console.Error<wbr/>.Write(''«format'', »''x'');</code><br/>or<br/><code>Console.Error<wbr/>.WriteLine(''«format'', »''x'');</code>
|-
| [[D (programming language)|D]]
| <code>''x'' = std.stdio.readln()</code>
| <code>std.stdio.write(''x'')</code><br/>or<br/><code>std.stdio.writeln(''x'')</code><br/>or<br/><code>std.stdio.writef(''format'', ''x'')</code><br/>or<br/><code>std.stdio.writefln(''format'', ''x'')</code>
| <code>stderr.write(''x'')</code><br/>or<br/><code>stderr.writeln(''x'')</code><br/>or<br/><code>std.stdio<wbr/>.writef(stderr, ''format'', ''x'')</code><br/>or<br/><code>std.stdio<wbr/>.writefln(stderr, ''format'', ''x'')</code>
|-
| [[Java (programming language)|Java]]
| <syntaxhighlight lang="java" inline>x = System.in.read();</syntaxhighlight><br/>or<br/><syntaxhighlight lang="java" inline>x = new Scanner(System.in).nextInt();</syntaxhighlight><br/>or<br/><syntaxhighlight lang="java" inline>x = new Scanner(System.in).nextLine();</syntaxhighlight>
| <code>System.out.print(''x'');</code><br/>or<br/><code>System.out.[[printf]](''format'', ''x'');</code><br/>or<br/><code>System.out.println(''x'');</code>
| <code>System.err.print(''x'');</code><br/>or<br/><code>System.err.[[printf]](''format'', ''x'');</code><br/>or<br/><code>System.err.println(''x'');</code>
|-
| [[Go (programming language)|Go]]
| <code>fmt.Scan(&''x'')</code><br/>or<br/><code>fmt.[[Scanf]](''format'', &''x'')</code><br/>or<br/><syntaxhighlight lang="go" inline>x = bufio.NewReader(os.Stdin).ReadString('\n')</syntaxhighlight>
| <code>fmt.Println(''x'')</code><br/>or<br/><code>fmt.[[Printf]](''format'', ''x'')</code>
| <code>fmt.Fprintln(os{{Not a typo|.}}Stderr, x)</code><br/>or<br/><code>fmt.[[Fprintf]](os{{Not a typo|.}}Stderr, ''format'', ''x'')</code>
|-
| [[Swift (programming language)|Swift]]
| <code>''x'' = readLine()</code> (2.x)
| <code>print(''x'')</code> (2.x)<br/><code>println(''x'')</code> (1.x)
|
|-
| [[JavaScript]]<br/><small>[[Client-side JavaScript|Web Browser implementation]]</small>
|
| <code>document.write(''x'')</code>
|
|-
| [[JavaScript]]<br/><small>[[Active Server Pages]]</small>
|
| <code>Response.Write(''x'')</code>
|
|-
| [[JavaScript]]<br/><small>[[Windows Script Host]]</small>
| <code>''x'' = WScript.StdIn.Read(''chars'')</code><br/>or<br/><code>''x'' = WScript.StdIn.ReadLine()</code>
| <code>WScript.Echo(''x'')</code><br/>or<br/><code>WScript.StdOut.Write(''x'')</code><br/>or<br/><code>WScript.StdOut.WriteLine(''x'')</code>
| <code>WScript.StdErr.Write(''x'')</code><br/>or<br/><code>WScript.StdErr.WriteLine(''x'')</code>
|-
| [[Common Lisp]]
| <syntaxhighlight lang="lisp" inline>(setf x (read-line))</syntaxhighlight>
| <code>(princ ''x'')</code><br/>or<br/><code>(format t ''format x'')</code>
| <syntaxhighlight lang="lisp" inline>(princ x *error-output*)</syntaxhighlight><br/>or<br/><code>{{codett|(format *error-output*|lisp}} ''format x'')</code>
|-
| [[Scheme (programming language)|Scheme]] ([[R6RS|R<sup>6</sup>RS]])
| <syntaxhighlight lang="scheme" inline>(define x (read-line))</syntaxhighlight>
| <code>(display ''x'')</code><br/>or<br/><code>{{codett|(format #t|scheme}} ''format x'')</code>
| <syntaxhighlight lang="scheme" inline>(display x (current-error-port))</syntaxhighlight><br/>or<br/><code>{{codett|(format (current-error-port)|scheme}} ''format x'')</code>
|-
| [[ISLISP]]
| <code>(setf x (read-line))</code>
| <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/>or<br/><code>readln(''x'');</code>
| <code>write(''x'');</code><br/>or<br/><code>writeln(''x'');</code>
| <code>write(stderr, ''x'');</code><br/>or<br/><code>writeln(stderr, ''x'');</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| <code>Input« ''prompt'',» ''x''</code>
| <code>Print ''x''</code><br/>or<br/><code>? ''x''</code>
| {{n/a}}
|-
| [[Visual Basic .NET]]
| <code>''x'' = Console.Read()</code><br/>or<br/><code>''x'' = Console.ReadLine()</code>
| <code>Console.Write(''«format'',»''x'')</code><br/>or<br/><code>Console.WriteLine(''«format'', »''x'')</code>
| <code>Console.Error<wbr/>.Write(''«format'', ''»x'')</code><br/>or<br/><code>Console.Error<wbr/>.WriteLine(''«format'', »''x'')</code>
|-
| [[Xojo]]
| <code>''x'' = StandardInputStream.Read()</code><br/>or<br/><code>''x'' = StandardInputStreame.ReadLine()</code>
| <code>StandardOutputStream.Write(''x'')</code><br/>or<br/><code>StandardOutputStream.WriteLine(''x'')</code>
| <code>StdErr.Write(''x'')</code><br/>or<br/><code>StdErr.WriteLine(''x'')</code>
|-
| [[Python (programming language)|Python]] 2.x
| <code>''x'' = raw_input(''«prompt»'')</code>
| <code>print ''x''</code><br/>or<br/><code>sys.stdout.write(''x'')</code>
| <code>{{codett|print >> sys.stderr,|python2}} ''x''</code><br/>or<br/><code>sys.stderr.write(''x'')</code>
|-
| [[Python (programming language)|Python]] 3.x
| <code>''x'' = input(''«prompt»'')</code>
| <code>print(''x«'', end=""»)</code>
| <code>print(''x«'', end=""», file=sys.stderr)</code>
|-
| [[S-Lang]]
| <code>[[fgets]] (&''x'', stdin)</code>
| <code>[[fputs]] (''x'', stdout)</code>
| <code>[[fputs]] (''x'', stderr)</code>
|-
| [[Fortran]]
| <code>READ(*,''format'') ''variable names'' </code><br/>or<br/><code>READ(INPUT_UNIT,''format'') ''variable names''</code>{{ref|Fortran standard units|[e]}}
| <code>WRITE(*,''format'') ''expressions'' </code><br/>or<br/><code>WRITE(OUTPUT_UNIT,''format'') ''expressions''</code>{{ref|Fortran standard units|[e]}}
| <code>WRITE(ERROR_UNIT,''format'') ''expressions''</code>{{ref|Fortran standard units|[e]}}
|-
| [[Forth (programming language)|Forth]]
| <code>''buffer length'' ACCEPT ''( # chars read )''<br/>KEY ''( char )''</code>
| <code>''buffer length'' TYPE<br/>''char'' EMIT</code>
| {{n/a}}
|-
| [[PHP]]
| <code>''$x'' = [[fgets]](STDIN);</code><br/>or<br/><code>''$x'' = [[fscanf]](STDIN, ''format'');</code>
| <code>print ''x'';</code><br/>or<br/><code>[[echo (command)|echo]] ''x'';</code><br/>or<br/><code>[[printf]](''format'', ''x'');</code>
| <code>[[fprintf]](STDERR, ''format'', ''x'');</code>
|-
| [[Perl]]
| <code>''$x'' = <>;</code><br/>or<br/><code>''$x'' = <STDIN>;</code>
| <code>print ''x'';</code><br/>or<br/><code>[[printf]] ''format'', ''x'';</code>
| <code>print STDERR ''x'';</code><br/>or<br/><code>[[printf]] STDERR ''format'', ''x'';</code>
|-
| [[Raku (programming language)|Raku]]
| <syntaxhighlight lang="raku" inline>$x = $*IN.get;</syntaxhighlight>
| <code>''x''.print</code><br/>or<br/><code>''x''.say</code>
| <code>''x''.note</code><br/>or<br/><syntaxhighlight lang="raku" inline>$*ERR.print(x)</syntaxhighlight><br/>or<br/><syntaxhighlight lang="raku" inline>$*ERR.say(x)</syntaxhighlight>
|-
| [[Ruby (programming language)|Ruby]]
| <code>''x'' = gets</code>
| <code>puts ''x''</code><br/>or<br/><code>[[printf]](''format'', ''x'')</code>
| <code>$stderr.puts(x)</code><br/>or<br/><code>$stderr.[[printf]](''format'', ''x'')</code>
|-
| [[Windows PowerShell]]
| <code>''$x'' = Read-Host«« -Prompt» ''text''»;</code><br/>or<br/><syntaxhighlight lang="ps1" inline>$x = [Console]::Read();</syntaxhighlight><br/>or<br/><syntaxhighlight lang="ps1" inline>$x = [Console]::ReadLine()</syntaxhighlight>
| <code>''x'';</code><br/>or<br/><code>Write-Output ''x'';</code><br/>or<br/><code>echo ''x''</code>
| <code>Write-Error ''x''</code>
|-
| [[OCaml]]
| <code>let ''x'' = read_int ()</code><br/>or<br/><code>let ''str'' = read_line ()</code><br/>or<br/><code>Scanf.[[scanf]] ''format'' (fun ''x ...'' <nowiki>-></nowiki> ''...'')</code>
| <code>print_int ''x''</code><br/>or<br/><code>print_endline ''str''</code><br/>or<br/><code>Printf.[[printf]] ''format x ...''</code>
| <code>prerr_int ''x''</code><br/>or<br/><code>prerr_endline ''str''</code><br/>or<br/><code>Printf.[[fprintf|eprintf]] ''format x ...''</code>
|-
| [[F Sharp (programming language)|F#]]
| <syntaxhighlight lang="f#" inline>let x = System.Console.ReadLine()</syntaxhighlight>
| <code>[[printf]] ''format x ...''</code><br/>or<br/><code>[[printf]]n ''format x ...''</code>
| <code>[[fprintf|eprintf]] ''format x ...''</code><br/>or<br/><code>[[fprintf|eprintf]]n ''format x ...''</code>
|-
| [[Standard ML]]
| <syntaxhighlight lang="sml" inline>val str = TextIO.inputLIne TextIO.stdIn</syntaxhighlight>
| <code>print ''str''</code>
| <code>{{codett|TextIO.output (TextIO.stdErr,|sml}}'' str'')</code>
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| <code>''x'' <- readLn</code><br/>or<br/><code>''str'' <nowiki><-</nowiki> getLine</code>
| <code>print ''x''</code><br/>or<br/><code>putStrLn ''str''</code>
| <code>hPrint stderr ''x''</code><br/>or<br/><code>hPutStrLn stderr ''str''</code>
|-
| [[COBOL]]
| <code>ACCEPT ''x''</code>
| <code>DISPLAY ''x''</code>
|
*For numbers: ''x'' = input()
*For strings: ''x'' = raw_input()
| print( ... ) <br> sys.stdout.write( ''string'' )
| sys.stderr.write( ''string'' )
|-
| [[S-Lang_(programming_language)|S-Lang]]
| fgets (&x, stdin)
| fputs (x, stdout)
| fputs (x, stderr)
|}
 
* {{note|ALGOL Unformatted|a}} ALGOL 68 additionally as the "unformatted" [[transput]] routines: <code>read</code>, <code>write</code>, <code>get</code>, and <code>put</code>.
== Reading arguments ==
* {{note|more c input|b}} <code>[[gets()|gets]](x)</code> and <code>[[fgets]](x, ''length'', stdin)</code> read unformatted text from stdin. Use of gets is not recommended.
 
* {{note|more c input|c}} <code>[[puts (C)|puts]](x)</code> and <code>[[fputs]](x, stdout)</code> write unformatted text to stdout.
* {{note|more c error output|d}} <code>fputs(x, stderr)</code> writes unformatted text to stderr
* {{note|Fortran standard units|e}} {{mono|INPUT_UNIT, OUTPUT_UNIT, ERROR_UNIT}} are defined in the {{mono|ISO_FORTRAN_ENV}} module.<ref>{{cite web|url=http://fortranwiki.org/fortran/show/iso_fortran_env|title=iso_fortran_env in Fortran Wiki|work=fortranwiki.org|access-date=30 January 2017}}</ref>
 
== Reading [[command-line argument]]s ==
{| class="wikitable"
{| class="wikitable sortable"
|-
!
! Argument values
! Argument counts
! Program name / Script name
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| C
| <code>Argument (''n'')</code>
| char **argv
| <code>Argument_Count</code>
| int argc
| <code>Command_Name</code>
|-
| [[C (programming language)|C]] ([[C99]])
| C++
| rowspan=3| <code>argv[''n'']</code>
| as above
| rowspan=3| <code>argc</code>
| as above
| rowspan=3| first argument
|-
| [[Objective-C]]
| Java
| ''string'' = args[''x''];
| ''integer'' = args.length;
|-
| Pascal[[C++]]
| ''string'' := ParamStr(''integer'');
| ''integer'' := ParamCount;
|-
| [[C Sharp (programming language)|C#]]
| Visual Basic
| rowspan=3| <code>args[''n'']</code>
| <code>args.Length</code>
| <code>Assembly.GetEntryAssembly()<wbr/>.Location;</code>
|-
| [[Java (programming language)|Java]]
| rowspan=2| <code>args.length</code>
| <!-- same as name of class containing ''main()'' --> <!-- not sure if that would yield the name of the exe/binary file of the program -->
|-
| [[D (programming language)|D]]
| first argument
|-
| [[JavaScript]]<br/><small>[[Windows Script Host]] implementation</small>
| <code>WScript.Arguments(''n'')</code>
| <code>WScript.Arguments.length</code>
| <code>WScript.ScriptName</code><br/>or<br/><code>WScript.ScriptFullName</code>
|-
| [[Go (programming language)|Go]]
| <code>os.Args[''n'']</code>
| <code>len(os.Args)</code>
| first argument
|-
| [[Rust (programming language)|Rust]]{{ref|Rust args|[a]}}
| <code>std::env::args().nth(''n'')</code><br/><code>std::env::args_os().nth(''n'')</code>
| {{code|2=rust|std::env::args().count()}}<br/>{{code|2=rust|std::env::args_os().count()}}
| {{code|2=rust|std::env::args().next()}}<br/>{{code|2=rust|std::env::args_os().next()}}
|-
| [[Swift (programming language)|Swift]]
| <code>Process.arguments[''n'']</code> or<br/><code>Process.unsafeArgv[''n'']</code>
| <code>Process.arguments.count</code> or<br/><code>Process.argc</code>
| first argument
|-
| [[Common Lisp]]
| {{dunno}}
| {{dunno}}
| {{dunno}}
|-
| [[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
|-
| [[ISLISP]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Pascal (programming language)|Pascal]]
| <code>ParamStr(''n'')</code>
| <code>ParamCount</code>
| first argument
|-
| [[Visual Basic (classic)|Visual Basic]]
| <code>Command</code>{{ref|unseparated|[b]}}
| {{n/a}}
| <code>App.Path</code>
|-
| [[Visual Basic .NET]]
| <code>CmdArgs(''n'')</code>
| <code>CmdArgs.Length</code>
| {{code|2=vbnet|[Assembly].GetEntryAssembly().Location}}
|-
| [[Xojo]]
| <code>System.CommandLine</code>
| (string parsing)
| <code>Application.ExecutableFile.Name</code>
|-
| [[Python (programming language)|Python]]
| <code>sys.argv[''n'']</code>
| <code>len(sys.argv)</code>
| first argument
|-
| [[S-Lang]]
| <code>__argv[''n'']</code>
| <code>__argc</code>
| first argument
|-
| [[Fortran]]
| <code>DO ''i'' = ''1'',''argc''{{indent|2}}CALL GET_COMMAND_ARGUMENT (''i'',''argv(i)'')<br/>ENDDO</code>
| <code>''argc'' = COMMAND_ARGUMENT_COUNT ()</code>
| <code>CALL GET_COMMAND_ARGUMENT (''0'',''progname'')</code>
|-
| [[PHP]]
| <code>$argv[''n'']</code>
| <code>$argc</code>
| first argument
|-
| [[Bash shell]]
| <code>$''n'' ($1, $2, $3, ''...'')</code><br/><code>$@</code> (all arguments)
| <code>$#</code>
| <code>$0</code>
|-
| [[Perl]]
| <code>$ARGV[''n'']</code>
| {{code|2=perl|scalar(@ARGV)}}
| <code>$0</code>
|-
| [[Raku (programming language)|Raku]]
| <code>@*ARGS[''n'']</code>
| {{code|2=raku|@*ARGS.elems}}
| <code>$PROGRAM_NAME</code>
|-
| [[Ruby (programming language)|Ruby]]
| <code>ARGV[''n'']</code>
| <code>ARGV.size</code>
| <code>$0</code>
|-
| [[Windows PowerShell]]
| <code>$args[''n'']</code>
| <code>$args.Length</code>
| <code>$MyInvocation.MyCommand<wbr/>.Name</code>
|-
| [[OCaml]]
| <code>Sys.argv.(''n'')</code>
| <code>Array.length Sys.argv</code>
| first argument
|-
| [[F Sharp (programming language)|F#]]
| <code>args.[''n'']</code>
| <code>args.Length</code>
| <code>Assembly.GetEntryAssembly()<wbr/>.Location</code>
|-
| [[Standard ML]]
| {{code|lang=sml|List.nth (CommandLine.arguments (), n)}}
| {{code|lang=sml|length (CommandLine.arguments ())}}
| {{code|lang=sml|CommandLine.name ()}}
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| {{code|lang=haskell|do { args <- System.getArgs; return length args !! n }}}
| {{code|lang=haskell|do { args <- System.getArgs; return length args }}}
| <code>System.getProgName</code>
|-
| [[COBOL]]
| colspan=2 | {{ref|COBOL Arguments|[c]}}
| {{n/a}}
|}
 
* {{note|Rust args|a}} In Rust, <code>std::env::args</code> and <code>std::env::args_os</code> return iterators, <code>std::env::Args</code> and <code>std::env::ArgsOs</code> respectively. <code>Args</code> converts each argument to a <code>String</code> and it panics if it reaches an argument that cannot be converted to [[UTF-8]]. <code>ArgsOs</code> returns a non-lossy representation of the raw strings from the operating system (<code>std::ffi::OsString</code>), which can be invalid UTF-8.
* {{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 <code>ACCEPT</code> statements.
 
== Execution of commands ==
{| class="wikitable sortable"
!
!Shell command
!Execute program
![[exec (operating system)|Replace current program with new executed program]]
|-
| [[Ada (programming language)|Ada]]<ref name="Ada_RM_2012" />
| colspan=3 align="center"| Not part of the language standard. Commonly done by compiler provided packages or by interfacing to C or [[POSIX]].<ref name="Ada_Execute_Command">{{cite web|url=http://rosettacode.org/wiki/Execute_a_system_command#Ada|title=Execute a system command – Rosetta Code|work=rosettacode.org|access-date=30 January 2017}}</ref>
|-
| [[C (programming language)|C]]
| rowspan=3| <code>[[system (C standard library)|system]]("''command''");</code>
|
| rowspan=2| <code>[[Exec (operating system)|execl]](''path'', ''args'');</code><br/>or<br/><code>[[Exec (operating system)|execv]](''path'', ''arglist'');</code>
|-
| [[C++]]
|
|-
| [[Objective-C]]
| Python
| <syntaxhighlight lang="objc" inline>[NSTask launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments];</syntaxhighlight>
| sys.argv
|
| len(sys.argv)
|-
| [[S-Lang_C Sharp (programming_languageprogramming language)|S-LangC#]]
|
| __argv
| rowspan=2| <code>System.Diagnostics<wbr/>.Process.Start(''path'', ''argstring'');</code>
| __argc
|
|-
| [[F Sharp (programming language)|F#]]
|
|
|-
| [[Go (programming language)|Go]]
|
| <code>exec.Run(''path'', ''argv'', ''envv'', ''dir'', exec.DevNull, exec.DevNull, exec.DevNull)</code>
| <code>os.Exec(''path'', ''argv'', ''envv'')</code>
|-
| [[Visual Basic (classic)|Visual Basic]]
| <code>Interaction.Shell(''command'' «,&nbsp;''WindowStyle''» «,&nbsp;''isWaitOnReturn''»)</code>
|
|
|-
| [[Visual Basic .NET]]
| <code>Microsoft.VisualBasic<wbr/>.Interaction.Shell(''command'' «,&nbsp;''WindowStyle''» «,&nbsp;''isWaitOnReturn''»)</code>
| <code>System.Diagnostics<wbr/>.Process.Start(''path'', ''argstring'')</code>
|
|-
| [[Xojo]]
| <code>Shell.Execute(''command'' «,&nbsp;''Parameters''»)</code>
| <code>FolderItem.Launch(''parameters'', ''activate'')</code>
| {{n/a}}
|-
| [[D (programming language)|D]]
| <code>std.process.system("''command''");</code>
|
| <code>std.process.execv(''path'', ''arglist'');</code>
|-
| [[Java (programming language)|Java]]
|
| <code>Runtime.exec(''command'');</code><br/>or<br/><code>new ProcessBuilder(command).start();</code>
|
|-
| [[JavaScript]]<br/><small>[[Windows Script Host]] implementation</small>
| <code>{{codett|WScript.CreateObject ("WScript.Shell").Run(|js}}''command'' «,&nbsp;''WindowStyle''» «,&nbsp;''isWaitOnReturn''»);</code>
| <code>WshShell.Exec(command)</code>
|
|-
| [[Common Lisp]]
| <code>(uiop:run-program ''command'')</code>
|
|
|-
| [[Scheme (programming language)|Scheme]]
| <code>(system ''command'')</code>
|
|
|-
| [[ISLISP]]
| {{n/a}}
| {{n/a}}
| {{n/a}}
|-
| [[Pascal (programming language)|Pascal]]
| <code>system(''command'');</code>
|
|
|-
| [[OCaml]]
| <code>Sys.command ''command'', Unix.open_process_full ''command env (stdout, stdin, stderr),...''</code>
| <code>Unix.create_process ''prog args new_stdin new_stdout new_stderr, ...''</code>
| <code>Unix.execv ''prog args''</code><br/>or<br/><code>Unix.execve ''prog args env''</code>
|-
| [[Standard ML]]
| <code>OS.Process.system ''command''</code>
| <code>Unix.execute (''path'', ''args'')</code>
| <code>Posix.Process.exec (''path'', ''args'')</code>
|-
| [[Haskell]] ([[Glasgow Haskell Compiler|GHC]])
| <code>System.system ''command''</code>
| <code>System.Process<wbr/>.runProcess ''path args ...''</code>
| <code>Posix.Process<wbr/>.executeFile ''path'' True ''args ...''</code>
|-
| [[Perl]]
| <code>system(''command'')</code><br/>or<br/><code>''$output'' = `''command''`</code><br/>or<br/><code>''$output'' = qx(''command'')</code>
|
| <code>exec(''path'', ''args'')</code>
|-
| [[Ruby (programming language)|Ruby]]
| <code>system(''command'')</code><br/>or<br/><code>''output'' = `''command''`</code>
|
| <code>exec(''path'', ''args'')</code>
|-
| [[PHP]]
| <code>system(''command'')</code><br/>or<br/><code>''$output'' = `''command''`</code><br/>or<br/><code>exec(''command'')</code><br/>or<br/><code>passthru(''command'')</code>
|
|
|-
| [[Python (programming language)|Python]]
| <code>os.system(''command'')</code><br/>or<br/><code>subprocess.Popen(''command'')</code>
| <code>subprocess.call(''["program", "arg1", "arg2", ...]'')</code>
| <code>os.execv(''path'', ''args'')</code>
|-
| [[S-Lang]]
| <code>system(''command'')</code>
|
|
|-
| [[Fortran]]
| <code>CALL EXECUTE_COMMAND_LINE (''COMMAND'' «, ''WAIT''» «, ''EXITSTAT''» «, ''CMDSTAT''» «, ''CMDMSG''»)</code>{{ref|Fortran 2008|[a]}}
|
|
|-
| [[Windows PowerShell]]
| <syntaxhighlight lang="ps1" inline>[Diagnostics.Process]::Start(command)</syntaxhighlight>
| <code>«Invoke-Item »''program arg1 arg2 ...''</code>
|
|-
| [[Bash shell]]
| <code>''output''=`''command''`</code><br/>or<br/><code>''output''=$(''command'')</code>
| <code>program arg1 arg2 ...</code>
|
|}
{{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 ==
{{Reflist}}
 
[[Category:Programming constructs]]
[[Category:Programming language comparisons|*Basic instructions]]
[[Category:Programming language topics]]