Comparison of programming languages (basic instructions) explained

This article compares a large number of programming languages by tabulating their data types, their expression, statement, and declaration syntax, and some common operating-system interfaces.__TOC__

Conventions of this article

Generally, var,, or is how variable names or other non-literal values to be interpreted by the reader are represented. The rest is literal code. Guillemets (and) enclose optional sections. indicates a necessary (whitespace) indentation.

The tables are not sorted lexicographically ascending by programming language name by default, and that some languages have entries in some tables but not others.

Type identifiers

Integers

8 bit (byte)16 bit (short integer)32 bit64 bit (long integer)Word sizeArbitrarily precise (bignum)
SignedUnsignedSignedUnsignedSignedUnsignedSignedUnsignedSignedUnsigned
Ada[1] range -2**7 .. 2**7 - 1range 0 .. 2**8 - 1 or mod 2**8range -2**15 .. 2**15 - 1range 0 .. 2**16 - 1 or mod 2**16range -2**31 .. 2**31 - 1range 0 .. 2**32 - 1 or mod 2**32range -2**63 .. 2**63 - 1mod 2**64Integerrange 0 .. 2**Integer'<wbr/>Size - 1 or mod Integer'<wbr/>Size
ALGOL 68 (variable-width)short short intshort intintlong intintlong long int
bytes and bits
C (C99 fixed-width)int8_tuint8_tint16_tuint16_tint32_tuint32_tint64_tuint64_tintptr_tsize_trowspan=5
C++ (C++11 fixed-width)
C (C99 variable-width)signed charunsigned charshortunsigned shortlongunsigned longlong longunsigned long longintunsigned int
C++ (C++11 variable-width)
Objective-C (Cocoa)signed char or int8_tunsigned char or uint8_tshort or int16_tunsigned short or uint16_tint or int32_tunsigned int or uint32_tlong long or int64_tunsigned long long or uint64_tNSInteger or longNSUInteger or unsigned long
C#sbytebyteshortushortintuintlongulongIntPtrUIntPtrSystem.Numerics.<wbr/>BigInteger
(.NET 4.0)
Javabytecharjava.math.<wbr/>BigInteger
Goint8uint8 or byteint16uint16int32uint32int64uint64intuintbig.Int
Rusti8u8i16u16i32u32i64u64isizeusize
SwiftInt8UInt8Int16UInt16Int32UInt32Int64UInt64IntUInt
DbyteubyteshortushortintuintlongulongBigInt
Common Lisp[2] (signed-byte 8)(unsigned-byte 8)(signed-byte 16)(unsigned-byte 16)(signed-byte 32)(unsigned-byte 32)(signed-byte 64)(unsigned-byte 64)bignum
Scheme
ISLISP[3] bignum
Pascal (FPC)shortintbytesmallintwordlongintlongwordint64qwordintegercardinal
Visual BasicByteIntegerLongrowspan=1
Visual Basic .NETSByteShortUShortIntegerUIntegerLongULongSystem.Numerics<wbr/>.BigInteger
(.NET 4.0)
FreeBasicByte or <nowiki>Integer<8></nowiki>UByte or <nowiki>UInteger<8></nowiki>| Short or <nowiki>Integer<16></nowiki>| UShort or <nowiki>UInteger<16></nowiki>| Long or <nowiki>Integer<32></nowiki>ULong or <nowiki>UInteger<32></nowiki>LongInt or <nowiki>Integer<64></nowiki>| ULongInt or <nowiki>UInteger<64></nowiki>| Integer| UInteger| |-| Python 2.x| colspan=2 | colspan=2 | colspan=2 | colspan=2 | int| | long|-| Python 3.x| colspan=2 | colspan=2 | colspan=2 | colspan=2 | colspan=2 | int|-| S-Lang| colspan=2 | colspan=2 | colspan=2 | colspan=2 | colspan=2 | |-| Fortran| INTEGER<wbr/>(KIND = n)| | INTEGER<wbr/>(KIND = n)| | INTEGER<wbr/>(KIND = n)| | INTEGER<wbr/>(KIND = n)| ||||-| PHP| colspan=2 | colspan=2 | int| | int| | colspan=2 | |-| Perl 5| colspan=2 | colspan=2 | colspan=2 | colspan=2 | colspan=2 | Math::BigInt|-| Raku| int8| uint8| int16| uint16| int32| uint32| int64| uint64| Int| colspan=2 |-| Ruby| colspan=2 | colspan=2 | colspan=2 | colspan=2 | Fixnum| | Bignum|-| Erlang| colspan=2 | colspan=2 | colspan=2 | colspan=2 | integer| | integer|-| Scala| Byte| | Short| Char| Int| | Long| | | | scala.math.BigInt|-| Seed7| | | | | | | integer| | | | bigInteger|-| Smalltalk| colspan=2 | colspan=2 | colspan=2 | colspan=2 | SmallInteger| | LargeInteger|-| Windows PowerShell| colspan=2 | colspan=2 | colspan=2 | colspan=2 | colspan=2 | |-| OCaml| colspan=2 | colspan=2 | int32| | rowspan=2| int64| | int or nativeint|| open Big_int;; or big_int|-| F#| sbyte| byte| int16| uint16| int32 or int| uint32| uint64| nativeint| unativeint| bigint|-| Standard ML| | Word8.word| colspan=2 | Int32.int| Word32.word| Int64.int| Word64.word| int| word| LargeInt.int or
IntInf.int|-| Haskell (GHC)| «import Int» or Int8| «import Word» or Word8| «import Int» or Int16| «import Word» or Word16| «import Int» or Int32| «import Word» or Word32| «import Int» or Int64| «import Word» or Word64| Int| «import Word» or Word| Integer|-| Eiffel| INTEGER_8| NATURAL_8| INTEGER_16| NATURAL_16| INTEGER_32| NATURAL_32| INTEGER_64| NATURAL_64| INTEGER| NATURAL| |-| COBOL| BINARY-CHAR «SIGNED»| BINARY-CHAR UNSIGNED| BINARY-SHORT «SIGNED»| BINARY-SHORT UNSIGNED| BINARY-LONG «SIGNED»| BINARY-LONG UNSIGNED| BINARY-DOUBLE «SIGNED»| BINARY-DOUBLE UNSIGNED| | | |-| Mathematica| colspan=2 | colspan=2 | colspan=2 | colspan=2 | colspan=2 | Integer|-| Wolfram Language| colspan=2 | colspan=2 | colspan=2 | colspan=2 | colspan=2 | Integer|}
  • The standard constants int shorts and int lengths can be used to determine how many shorts and longs can be usefully prefixed to short int and long int. The actual sizes of short int, int, and long int are available as the constants short max int, max int, and long max int etc.
  • Commonly used for characters.
  • The ALGOL 68, C and C++ languages do not specify the exact width of the integer types short, int, long, and (C99, C++11) long long, so they are implementation-dependent. In C and C++ short, long, and long long types are required to be at least 16, 32, and 64 bits wide, respectively, but can be more. The int type is required to be at least as wide as short and at most as wide as long, 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 also define the [u]intN_t exact-width types in the stdint.h header. See C syntax#Integral types for more information. In addition the types size_t and ptrdiff_t 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.
  • Perl 5 does not have distinct types. Integers, floating point numbers, strings, etc. are all considered "scalars".
  • PHP has two arbitrary-precision libraries. The BCMath library just uses strings as datatype. The GMP library uses an internal "resource" type.
  • The value of n is provided by the SELECTED_INT_KIND[4] intrinsic function.
  • ALGOL 68G's runtime option --precision "number" can set precision for long long ints to the required "number" significant digits. The standard constants long long int width and long long max int can be used to determine actual precision.
  • COBOL allows the specification of a required precision and will automatically select an available type capable of representing the specified precision. "PIC S9999", 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.
  • 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 and one supporting arbitrary sized integers . Arithmetic operations support polymorphic arguments and return the result in the most appropriate compact representation.
  • 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 (range 1 .. Integer'Last) and Natural (range 0 .. Integer'Last). Short_Short_Integer (8 bits), Short_Integer (16 bits) and Long_Integer (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.
  • Ada modulo types implement modulo arithmetic in all operations, i.e. no range violations are possible. Modulos are not restricted to powers of two.
  • Commonly used for characters like Java's char.
  • int in PHP has the same width as long type in C has on that system.
  • Erlang is dynamically typed. The type identifiers are usually used to specify types of record fields and the argument and return types of functions.[5]
  • When it exceeds one word.[6]
Single precisionDouble precisionOther precisionProcessor dependent
AdaFloatLong_Float
ALGOL 68reallong realshort real, long long real, etc.
Cfloatdoublelong double
C++ (STL)
Objective-C (Cocoa)CGFloat
C#floatrowspan=4
Java
Gofloat32float64
Rustf32f64
SwiftFloat or Float32Double or Float64Float80CGFloat
Dfloatdoublereal
Common Lispsingle-floatdouble-floatfloat, short-float, long-float
Scheme
ISLISP
Pascal (FPC)singledoublereal
Visual BasicSingleDoublerowspan=3
Visual Basic .NET
Xojo
Pythonfloat
JavaScriptNumber[7]
S-Lang
FortranREAL(KIND = n)
PHPfloat
Perl
Rakunum32num64Num
RubyFloatrowspan=4
ScalaFloatDouble
Seed7float
SmalltalkFloatDouble
Windows PowerShell
OCamlfloatrowspan=3
F#float32
Standard MLreal
Haskell (GHC)FloatDouble
EiffelREAL_32REAL_64
COBOLFLOAT-BINARY-7FLOAT-BINARY-34FLOAT-SHORT, FLOAT-LONG, FLOAT-EXTENDED
MathematicaReal
  • The standard constants real shorts and real lengths can be used to determine how many shorts and longs can be usefully prefixed to short real and long real. The actual sizes of short real, real, and long real are available as the constants short max real, max real and long max real etc. With the constants short small real, small real and long small real available for each type's machine epsilon.
  • declarations of single precision often are not honored
  • The value of n is provided by the SELECTED_REAL_KIND[8] intrinsic function.
  • ALGOL 68G's runtime option --precision "number" can set precision for long long reals to the required "number" significant digits. The standard constants long long real width and long long max real can be used to determine actual precision.
  • These IEEE floating-point types will be introduced in the next COBOL standard.
  • Same size as double on many implementations.
  • Swift supports 80-bit extended precision floating point type, equivalent to long double in C languages.

Complex numbers

IntegerSingle precisionDouble precisionHalf and Quadruple precision etc.
AdaComplexComplexComplex
ALGOL 68compllong compl etc.short compl etc. and long long compl etc.
C (C99)[9] float complexdouble complexrowspan=7
C++ (STL)<nowiki>std::complex<float></nowiki>| <nowiki>std::complex<double></nowiki>
C#System.Numerics.Complex
(.NET 4.0)
Java
Gocomplex64complex128
Dcfloatcdouble
Objective-C
Common Lisp(complex integer)(complex single-float)(complex double-float)complex
Schemerowspan=4
Pascal
Visual Basic
Visual Basic .NETSystem.Numerics.Complex
(.NET 4.0)
PerlMath::Complex
Rakucomplex64complex128Complex
Pythoncomplexrowspan=15
JavaScript
S-Lang
FortranCOMPLEX(KIND = n)
RubyComplexComplex
Scala
Seed7complex
SmalltalkComplexComplexComplex
Windows PowerShell
OCamlComplex.t
F#System.Numerics.Complex
(.NET 4.0)
Standard ML
Haskell (GHC)Complex{{Not a typo|.}}Complex FloatComplex{{Not a typo|.}}Complex Double
Eiffel
COBOL
MathematicaComplexComplex
  • The value of n is provided by the SELECTED_REAL_KIND intrinsic function.
  • Generic type which can be instantiated with any base floating point type.

Other variable types

TextBooleanEnumerationObject/Universal
CharacterString
AdaCharacterString, Bounded_String, Unbounded_StringBoolean(''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'')tagged null record
ALGOL 68charstring, bytesbool, bits - User defined
C (C99)char, wchar_tboolenum ''«name»'' { ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' };[[void type|void]] [[pointer (computer programming)|*]]
C++ (STL)«std::»string
Objective-CunicharNSString *BOOLid
C#charstringboolenum ''name'' { ''item<sub>1</sub>''« = ''value''», ''item<sub>2</sub>''« = ''value''», ''...'' }object
JavaStringbooleanenum ''name'' { ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }Object
Gobyte, runestringboolconst (<br/>{{Spaces|3}}''item{{sub|1}}'' = ''iota''<br/>{{Spaces|3}}''item{{sub|2}}''<br/>{{Spaces|3}}''...''<br/>)interface{}
RustcharStringboolenum ''name'' { ''item{{sub|1}}''« = ''value''», ''item{{sub|2}}''« = ''value''», ''...'' }std::any::Any
SwiftCharacterStringBoolenum ''name'' { case ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }Any
Dcharstringboolenum ''name'' { ''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'' }std.variant.Variant
Common Lispcharacterstringboolean(member ''item<sub>1</sub>'' ''item<sub>2</sub>'' ''...'')t
Scheme
ISLISP
Pascal (ISO)charboolean(''item<sub>1</sub>'', ''item<sub>2</sub>'', ''...'')
Object Pascal (Delphi)stringvariant
Visual BasicStringBooleanEnum ''name''<br/>{{Spaces|3}}''item{{sub|1}}'' «= ''value''»<br/>{{Spaces|3}}''item{{sub|2}}'' «= ''value»<br/>{{Spaces|3}}...''<br/>End Enum<nowiki>[[Variant type|Variant]]</nowiki>
Visual Basic .NETCharObject
XojoObject or Variant
Pythonstrboolfrom enum import Enum<br/>class Name(Enum):<br/>{{Spaces|3}}''item{{sub|1}}'' = ''value''<br/>{{Spaces|3}}''item{{sub|2}}'' = ''value''<br/>{{Spaces|3}}''...''object
JavaScriptStringBooleanObject
S-Lang
FortranCHARACTER(LEN = *)CHARACTER(LEN = :), allocatableLOGICAL(KIND = n)CLASS(*)
PHPstringbool(type declaration omitted)
PerlUNIVERSAL
RakuCharStrBoolenum ''name<item<sub>1</sub> item<sub>2</sub> ...>''
enum ''name <<:item<sub>1</sub>(value) :item<sub>2</sub>(value) ..>>''
Mu
RubyStringObjectObject
ScalaCharStringBooleanobject ''name'' extends Enumeration {<br/>{{Spaces|3}}''val item{{sub|1}}, item{{sub|2}}, ... = Value''<br/>}Any
Seed7charstringbooleanconst type'': name'' is new enum<br/>{{Spaces|3}}''item{{sub|1}},''<br/>{{Spaces|3}}''item{{sub|2}},''<br/>{{Spaces|3}}''...''<br/>end enum;
Windows PowerShell
OCamlcharstringbool
F#type ''name'' = ''item<sub>1</sub>'' = ''value'' {{pipe}}''item<sub>2</sub>'' = ''value'' {{pipe}} ''...''obj
Standard ML
Haskell (GHC)CharStringBool
EiffelCHARACTERSTRINGBOOLEANANY
COBOLPIC X''PIC X(''string length'')'' or PIC&nbsp;X«X...»''PIC 1«(''number of digits'')»'' or PIC&nbsp;1«1...»OBJECT REFERENCE
MathematicaString
  • specifically, strings of arbitrary length and automatically managed.
  • This language represents a boolean as an integer where false is represented as a value of zero and true by a non-zero value.
  • All values evaluate to either true or false. Everything in TrueClass evaluates to true and everything in FalseClass evaluates to false.
  • This language does not have a separate character type. Characters are represented as strings of length 1.
  • Enumerations in this language are algebraic types with only nullary constructors
  • The value of n is provided by the SELECTED_INT_KIND intrinsic function.

Derived types

fixed size arraydynamic size array
one-dimensional arraymultidimensional arrayone-dimensional arraymultidimensional array
Adaarray (''&lt;first> ''..'' &lt;last>'') of'' &lt;type>''
or
array (''&lt;discrete_type>'') of'' &lt;type>''
array (''&lt;first<sub>1</sub>> ''..'' &lt;last<sub>1</sub>>'','' &lt;first<sub>2</sub>> ''..'' &lt;last<sub>2</sub>>'', ''...'') of'' &lt;type>''
or
array (''&lt;discrete_type<sub>1</sub>>'','' &lt;discrete_type<sub>2</sub>>'','' ...'') of'' &lt;type>''
array (''&lt;discrete_type> ''range <>) of'' &lt;type>''array (''&lt;discrete_type<sub>1</sub>> ''range <>,'' <discrete_type<sub>2</sub>> ''range <>, ''...'') of'' &lt;type>''
ALGOL 68[''first'':''last'']<wbr/>«modename»
or simply:
[''size'']<wbr/>«modename»
[''first<sub>1</sub>'':''last<sub>1</sub>'','' first<sub>2</sub>'':''last<sub>2</sub>'']<wbr/>«modename»
or
[''first<sub>1</sub>'':''last<sub>1</sub>''][''first<sub>2</sub>'':''last<sub>2</sub>'']<wbr/>«modename»
etc.
flex[''first'':''last'']<wbr/>«modename»
or simply:
flex[''size'']<wbr/>«modename»
flex[''first<sub>1</sub>'':''last<sub>1</sub>'','' first<sub>2</sub>'':''last<sub>2</sub>'']<wbr/>«modename»
or
flex[''first<sub>1</sub>'':''last<sub>1</sub>'']<wbr/>flex[''first<sub>2</sub>'':''last<sub>2</sub>'']<wbr/>«modename» ''etc.''
C (C99)''type name''[''size'']''type name''[''size<sub>1</sub>''][''size<sub>2</sub>'']''type'' *''name''
or within a block:
''int n = ...; type name''[''n'']
C++ (STL)[[std::array|«std::»array]]<''type, size''>(C++11)[[std::vector|«std::»vector]]<''type''>
C#''type''[]''type''[{{Not a typo|,,}}''...'']System<wbr/>.Collections<wbr/>.ArrayList
or
System<wbr/>.Collections<wbr/>.Generic<wbr/>.List<wbr/><''type''>
Java''type''[]''type''[][]''...''ArrayList ''or'' ArrayList<''type''>
D''type''[''size'']''type''[''size<sub>1</sub>''][''size<sub>2</sub>'']''type''[]
Go[''size'']''type''[''size<sub>1</sub>''][''size<sub>2</sub>'']''...type''[]type[][]type
Rust[''type; size''][<nowiki/>[''type; size<sub>1</sub>'']''; size<sub>2</sub>'']Vec<''type''>Vec<Vec<''type''>>
Swift[''type''] or Array<''type''><nowiki>[[</nowiki>''type''<nowiki>]]</nowiki> or Array<Array<''type''>>
Objective-CNSArrayNSMutableArray
JavaScriptArray
Common Lisp(simple-array type (dimension))(simple-array type (dimension1 dimension2))(array type (dimension))(array type (dimension1 dimension2))
Scheme
ISLISP
Pascalarray[''first''..''last''] of ''type''array[''first<sub>1</sub>''..''last<sub>1</sub>''] of array[''first<sub>2</sub>''..''last<sub>2</sub>'']'' ...'' of ''type''
or
array[''first<sub>1</sub>''..''last<sub>1</sub>'','' first<sub>2</sub>''..''last<sub>2</sub>'','' ...''] of ''type''
Object Pascal (Delphi)array of'' type''array of array ''...'' of ''type''
Visual BasicDim x(''last'') As ''type''Dim x(''last<sub>1</sub>'', ''last<sub>2</sub>'',''...'') As ''type''
Visual Basic .NET''type''''type''({{Not a typo|,,}}''...'')System<wbr/>.Collections<wbr/>.ArrayList
or
System<wbr/>.Collections<wbr/>.Generic<wbr/>.List<wbr/>(Of ''type'')
Pythonlist
S-Langx = ''type''[''size''];x = ''type''[''size<sub>1</sub>'','' size<sub>2</sub>'', ''...''];
Fortran''type'' :: ''name''(''size'')''type'' :: ''name''(''size''<sub>1</sub>, ''size<sub>2</sub>'',...)''type'', ALLOCATABLE :: ''name''(:)''type'', ALLOCATABLE :: ''name''(:,:,...)
PHParray
Perl
RakuArray[''type''] ''or'' Array of ''type''
Rubyx = Array.new(''size<sub>1</sub>''){ Array.new(''size<sub>2</sub>'') }Array
ScalaArray[''type'']Array[''...''[Array[''type'']]''...'']ArrayBuffer[''type'']
Seed7array ''type''
or
array [''idxType''] ''type''
array array ''type''
or
array [''idxType''] array [''idxType''] ''type''
array ''type''
or
array [''idxType''] ''type''
array array ''type''
or
array [''idxType''] array [''idxType''] ''type''
SmalltalkArrayOrderedCollection
Windows PowerShell''type''[]''type''[{{Not a typo|,,}}''...'']
OCaml''type'' array''type'' array ''...'' array
F#''type'' []
or
''type'' array
''type'' [{{Not a typo|,,}}''...'']System<wbr/>.Collections<wbr/>.ArrayList
or
System<wbr/>.Collections<wbr/>.Generic<wbr/>.List<wbr/><''type''>
Standard ML''type'' vector ''or type'' array
Haskell (GHC)x = Array.array (0, ''size''-1) ''list_of_association_pairs''x = Array.array ((0, 0,''...''), (''size<sub>1</sub>''-1, ''size<sub>2</sub>''-1,''...'')) ''list_of_association_pairs''
COBOL''level-number type'' OCCURS ''size'' «TIMES».''level-number type'' OCCURS ''min-size'' TO ''max-size'' «TIMES» DEPENDING «ON» ''size''.
  • In most expressions (except the [[sizeof]] and & 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.
  • The C-like ''type'' x[] works in Java, however ''type''[] x is the preferred form of array declaration.
  • Subranges are used to define the bounds of the array.
  • JavaScript's array are a special kind of object.
  • The DEPENDING ON clause in COBOL does not create a true variable length array and will always allocate the maximum size of the array.

Other types

Simple composite typesAlgebraic data typesUnions
RecordsTuple expression
Adatype ''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'']''Any combination of records, unions, and enumerations (as well as references to those, enabling recursive types).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
ALGOL 68struct ''(''modename ''«fieldname»,'' ...'');''Required types and operators can be user-definedunion ''(''modename'','' ...'');''
C (C99)struct ''«name»'' {''type name'';''...''};union {''type name'';''...''};
Objective-C
C++struct ''«name»'' {''type name'';''...''};[[C++11#Tuple types|«std::»tuple]]<''type{{sub|1}}..type{{sub|n}}''>
C#struct ''name'' {''type name'';''...''}(''val{{sub|1}}'', ''val{{sub|2}}'', ''...'')rowspan=3
Java
JavaScript
Dstruct ''name'' {''type name'';''...''}std.variant.Algebraic''!(type,...)''union {''type name'';''...''}
Gostruct { {{indent|2}}''«name» type''{{indent|2}}''...''<br/>}
Ruststruct name {''name:'' type'', ...''}(''val{{sub|1}}'','' val{{sub|2}}'', ''...'')enum name { ''Foo''(''types'')'', ...''}union name {''name:'' type'', ...''}
Swiftstruct ''name'' {''{{indent|2}}''var'' name «'':'' type»{{indent|2}}...<br/>''}(''«name{{sub|1}}'':''» val{{sub|1}}'', ''«name{{sub|2}}'':''» val{{sub|2}}'', ''«name{{sub|3}}'':''» val{{sub|3}}'', ''...'')enum ''name'' { case ''Foo«''(''types'')» case ''Bar'' «(''types'')» ''...'' }
Common Lisp(defstruct name slot-name (slot-name initial-value) (slot-name initial-value :type type) ...)(cons ''val{{sub|1}} val{{sub|2}}'')
Scheme
ISLISP
Pascalrecord{{indent|2}}''name'': ''type'';{{indent|2}}''...<br/>''endrecord{{indent|2}}case ''type'' of{{indent|2}}''value'': (''types'');{{indent|2}}''...''<br/>end
Visual Basic
Visual Basic .NETStructure ''name''{{indent|2}}Dim ''name'' As ''type''{{indent|2}}''...''<br/>End Structure(''val{{sub|1}}'', ''val{{sub|2}}'', ''...'')
Python«(''»val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'' «)»
S-Langstruct {''name [=value], ...''}
FortranTYPE ''name{{indent|2}}type'' :: ''name{{indent|2}}...<br/>''END TYPE
PHP
Perlrowspan=3
Raku
Ruby
Scalacase class ''name''(«''var''» ''name'': ''type'', ''...'')(''val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'')abstract class ''name''{{indent|2}}case class ''Foo''(«''parameters''») extends ''name''{{indent|2}}case class ''Bar''(«''parameters''») extends ''name''{{indent|2}}''...''
or
abstract class ''name''{{indent|2}}case object ''Foo'' extends ''name''{{indent|2}}case object ''Bar'' extends ''name''{{indent|2}}''...''
or a combination of case classes and case objects
Windows PowerShell
OCamltype ''name'' = {«''mutable''» ''name'' : ''type'';''...''}«(»''val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'' «)»type ''name'' = ''Foo'' «of ''type''» {{pipe}} ''Bar'' «of ''type''» {{pipe}} ''...''rowspan=4
F#
Standard MLtype ''name'' = {''name'' : ''type'',''...''}(''val{{sub|1}}'', ''val{{sub|2}}'', ''val{{sub|3}}'', ''...'')datatype ''name'' = ''Foo'' «of ''type''» {{pipe}} ''Bar'' «of ''type''» {{pipe}} ''...''
Haskelldata ''Name'' = ''Constr'' {''name'' :: ''type'',''...''}data ''Name'' = ''Foo'' «''types''» {{pipe}} ''Bar'' «''types''» {{pipe}} ''...''
COBOL''level-number name type clauses''.{{indent|2}}''level-number+n name type clauses''.{{indent|2}}''...''''name'' REDEFINES ''variable type''.
  • Only classes are supported.
  • structs in C++ are actually classes, but have default public visibility and are also POD objects. C++11 extended this further, to make classes act identically to POD objects in many more cases.
  • pair only
  • 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.
  • Enumerations in this language are algebraic types with only nullary constructors

Variable and constant declarations

variableconstanttype synonym
Ada''identifier'' : ''type«'' := ''initial_value»''''identifier'' : constant ''type'' := ''final_value''subtype ''identifier'' is ''type''
ALGOL 68modename name« := ''initial_value''»;modename name = ''value'';[[typedef|mode]] synonym = modename;
C (C99)''type name''« = ''initial_value''»;enum{ ''name'' = ''value'' };[[typedef]] ''type synonym'';
Objective-C
C++const ''type name'' = ''value'';
C#''type name<sub>1</sub>''« = ''initial_value''», ''name<sub>2</sub>''« = ''initial_value''», ''...'';
or
var ''name'' = ''initial_value'';
const ''type name'' = ''value'', ''name'' = ''value'', ''...'';
or
readonly ''type name'' = ''value'', ''name'' = ''value'', ''...'' ;
using ''synonym'' = ''type'';
D''type name''« = ''initial_value''»;
or
auto ''name'' = ''value'';
const ''type name'' = ''value'';
or
immutable ''type name'' = ''value'';
alias ''type synonym'';
Java''type name''« = ''initial_value''»;final ''type name'' = ''value'';rowspan=2
JavaScriptvar ''name''« = ''initial_value''»; or
let ''name''« = ''initial_value''»; (since ECMAScript 2015)
const ''name'' = ''value''; (since ECMAScript 2015)
Govar ''name type''« = ''initial_value''»
or
''name'' := ''initial_value''
const ''name «type»'' = ''value''type ''synonym type''
Rustlet mut ''name''«: ''type''»« = ''initial_value''»;
static mut ''NAME'': ''type'' = ''value'';
let ''name''«: ''type''»« = ''initial_value''»;
const ''NAME'': ''type'' = ''value'';

static ''NAME'': ''type'' = ''value'';
type ''synonym'' = ''typename'';
Swiftvar ''name'' «: ''type''»« = ''initial_value''»let ''name'' «: ''type''» = ''value''typealias ''synonym'' = ''type''
Common Lisp(defparameter ''name initial-value'')
or
(defvar ''name initial-value'')
(defconstant ''name value'')(deftype ''synonym'' <nowiki>'</nowiki>''type'')|-| Scheme| (define ''name initial_value'')|||-| ISLISP| (defglobal ''name initial_value'')
or
(defdynamic ''name initial_value'')| (defconstant ''name value'')| |-| Pascal| ''name'': ''type''« = ''initial_value''»| ''name'' = ''value''| ''synonym'' = ''type''|-| Visual Basic| Dim ''name'' «As ''type''»| rowspan=3| See notes to left.Constants use the same syntax, and:
  • use Const instead of Dim
  • have a restriction to only certain primitive types
    Const ''name<sub>1</sub>'' «As ''type''» = ''value'', ''name<sub>2</sub>'' «As ''type»'' = ''value, ...''

||-| Visual Basic .NET[10] | The variable declaration syntax of VB.NET is unusually difficult to precisely describe.Given that there exist the identifier suffixes ("modifiers"):

  • type_character, available as an alternative to an As clause for some primitive data types;
  • nullable_specifier; and
  • array_specifier;

and that

  • a modified_identifier is of the form identifier«type_character»«nullable_specifier»«array_specifier»;
  • a modified_identifier_list is a comma-separated list of two or more occurrences of modified_identifier; and
  • a declarator_list is a comma-separated list of declarators, which can be of the form
    • ''identifier'' As ''object_creation_expression'' (object initializer declarator),
    • ''modified_identifier'' «As ''non_array_type''«''array_rank_specifier''»»« = ''initial_value»'' (single declarator), or
    • ''modified_identifier_list'' «As ''«non_array_type''««''array_rank_specifier''»» (multiple declarator);

valid declaration statements are of the formDim ''declarator_list'',where, for the purpose of semantic analysis, to convert the declarator_list to a list of only single declarators:

  • The As clauses of each multiple declarator is distributed over its modified_identifier_list
  • The As New ''type...'' of each object initializer declarator is replaced with As ''type'' = New ''type...''

and for which, for each identifier,

  • a type_character and As clause do not both appear;
  • if an As clause is present,
    • an array_rank_specifier does not appear both as a modification of the identifier and on the type of the As clause;
  • an unmodified_type can be determined, by the rule that,
    • if a type_character or As clause is present,
      • unmodified_type is that specified by such construct,
    • and that otherwise,
      • either Option Infer must be on and the identifier must have an initializer, in which case unmodified_type is that of the initializer, or
      • Option Strict must be off, in which case unmodified_type is Object;
  • its final_type is its unmodified_type prepended before its modifiers;
  • its final_type is a valid type; and
  • if an initial_value is present,
    • either Option Strict is on and initial_value has a widening conversion to final_type, or
    • Option Strict is off and initial_value has a narrowing conversion to final_type.

If Option Explicit is off, variables do not require explicit declaration; they are declared implicitly when used:<nowiki>name = initial_value</nowiki>| Imports ''synonym'' = ''type''|-| Xojo| Dim ''name'' «As ''type''»« = ''initial_value»''| |-| Python| ''name«: type»'' = ''initial_value''| rowspan=2 | ''synonym'' = ''type''|-| CoffeeScript| ''name'' = ''initial_value''| ''name'' = ''initial_value''|-| S-Lang| ''name'' = ''initial_value'';|| typedef struct {...} ''typename''|-| Fortran| ''type'' :: ''name''| ''type'', PARAMETER :: ''name'' = ''value''||-| PHP| $''name'' = ''initial_value'';| define("''name''", ''value'');<br/>const ''name'' = ''value (5.3+)''| rowspan=2 |-| Perl| «my» $''name''« = ''initial_value''»;| use constant ''name'' => ''value'';|-| Raku| «my «''type''»» ''$name«'' = ''initial_value''»;| «my «''type''»» constant ''name'' = ''value'';| ::''synonym'' ::= ''type''|-| Ruby| ''name'' = ''initial_value''| ''Name'' = ''value''| ''synonym'' = ''type''|-| Scala| var ''name''«: ''type''» = ''initial_value''| val ''name''«: ''type''» = ''value''| type ''synonym'' = ''type''|-| Windows PowerShell| «[''type'']» $''name'' = ''initial_value''| | |-| Bash shell| name=''initial_value''| | |-| OCaml| let ''name''« : ''type'' ref» = ref ''value''| rowspan=2| let ''name'' «: ''type''» = ''value''| rowspan=3| type ''synonym'' = ''type''|-| F#| let mutable ''name'' «: ''type''» = ''value''|-| Standard ML| val ''name'' «: ''type'' ref» = ref ''value''| val ''name'' «: ''type''» = ''value''|-| Haskell|| «''name''::''type'';» ''name'' = ''value''| type ''Synonym'' = ''type''|-| Forth| VARIABLE ''name'' (in some systems use ''value'' VARIABLE ''name'' instead)| ''value'' CONSTANT ''name''||-| COBOL| ''level-number name type clauses''.| «0»1 ''name'' CONSTANT «AS» ''value''.| ''level-number name type clauses'' «IS» TYPEDEF.|-| Mathematica| name=''initial_value''| | |}

  • Pascal has declaration blocks. See functions.
  • Types are just regular objects, so you can just assign them.
  • In Perl, the "my" keyword scopes the variable into the block.
  • 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 ! and <nowiki>:=</nowiki> operators, respectively.
  • 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.
  • In Rust, if no initial value is given to a let or let mut variable and it is never assigned to later, there is an "unused variable" warning. If no value is provided for a const or static or static mut variable, there is an error. There is a "non-upper-case globals" error for non-uppercase const variables. After it is defined, a static mut variable can only be assigned to in an unsafe block or function.

Conditional statements

ifelse ifselect caseconditional expression
Adaif ''condition'' then{{indent|2}}''statements''<br/>«else{{indent|2}}''statements''»<br/>end ifif ''condition{{sub|1}}'' then{{indent|2}}''statements''<br/>elsif ''condition{{sub|2}}'' then{{indent|2}}''statements''<br/>''...''<br/>«else{{indent|2}}''statements''»<br/>end ifcase ''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(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/>)
or
(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/>)
Seed7if ''condition'' then{{indent|2}}''statements''<br/>«else{{indent|2}}''statements''»<br/>end ifif ''condition{{sub|1}}'' then{{indent|2}}''statements''<br/>elsif ''condition{{sub|2}}'' then{{indent|2}}''statements''<br/>''...''<br/>«else{{indent|2}}''statements''»<br/>end ifcase ''expression'' of{{indent|2}}when ''set1'' : ''statements''{{indent|2}}''...''{{indent|2}}«otherwise: ''statements''»<br/>end case
Modula-2if ''condition'' then{{indent|2}}''statements''<br/>«else{{indent|2}}''statements''»<br/>endif ''condition{{sub|1}}'' then{{indent|2}}''statements''<br/>elsif ''condition{{sub|2}}'' then{{indent|2}}''statements''<br/>''...''<br/>«else{{indent|2}}''statements''»<br/>endcase ''expression'' of{{indent|2}}''caseLabelList'' : ''statements'' {{pipe}}{{indent|2}}''...''{{indent|2}}«else ''statements''»<br/>end
ALGOL 68if ''condition'' then ''statements'' «else ''statements''» fiif ''condition'' then ''statements'' elif ''condition'' then ''statements'' ficase ''switch'' in ''statements, statements«,...'' out ''statements''» esac(condition valueIfTrue valueIfFalse)
ALGOL 68
(brief form)
(condition statements «statements»)(condition statements

condition

statements)(variable statements,... «statements»)
APL:If ''condition''{{indent|2}}''instructions''<br/>«:Else{{indent|2}}''instructions''»<br/>:EndIf:If ''condition''{{indent|2}}''instructions''<br/>:ElseIf ''condition''{{indent|2}}''instructions''<br/>''...''<br/>«:Else{{indent|2}}''instructions''»<br/>:EndIf:Select ''expression''{{indent|2}}:Case ''case1''{{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}«:Else{{indent|4}}''instructions''»<br/>:EndSelect{''condition'':''valueIfTrue'' ⋄ ''valueIfFalse''}
C (C99)if (''condition'') ''instructions''<br/>«else ''instructions''»
instructions can be a single statement or a block in the form of: { ''statements'' }
if (''condition'') ''instructions''<br/>else if (''condition'') ''instructions''<br/>''...''<br/>«else ''instructions»''
or
if (''condition'') ''instructions''<br/>else { if (''condition'') ''instructions'' }
switch (''variable'') { {{indent|2}}case ''case1'': ''instructions'' «; break;»{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br/>}''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''
Objective-C
C++ (STL)
D
Java
JavaScript
PHP
C#if (''condition'') ''instructions''<br/>«else ''instructions''»instructions can be a single statement or a block in the form of: { ''statements'' }if (''condition'') ''instructions''<br/>else if (''condition'') ''instructions''<br/>''...''<br/>«else ''instructions''»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/>}All non-empty cases must end with a break or goto case statement (that is, they are not allowed to fall-through to the next case).The default case is not required to come last.''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''
Windows PowerShellif (''condition'') ''instruction''<br/>«else ''instructions''»if (''condition'') { ''instructions'' }<br/>elseif (''condition'') { ''instructions'' }<br/>''...''<br/>«else { ''instructions'' }»switch (''variable'') { ''case1''{''instructions'' «break;» } ''...'' «default { ''instructions'' }»}
Goif ''condition'' {''instructions''}<br/>«else {''instructions''}»if ''condition'' {''instructions''}<br/>else if ''condition'' {''instructions''}<br/>''...''<br/>«else {''instructions''}»
or
switch { {{indent|2}}case ''condition'': ''instructions''{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br/>}
switch ''variable'' { {{indent|2}}case ''case<sub>1</sub>'': ''instructions''{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br/>}
Swiftif ''condition'' {''instructions''}<br/>«else {''instructions''}»if ''condition'' {''instructions''}<br/>else if ''condition'' {''instructions''}<br/>''...''<br/>«else {''instructions''}»switch ''variable'' { {{indent|2}}case ''case<sub>1</sub>'': ''instructions''{{indent|2}}''...''{{indent|2}}«default: ''instructions''»<br/>}
Perlif (''condition'') {''instructions''}<br/>«else {''instructions''}»
or
unless (''notcondition'') {''instructions''}<br/>«else {''instructions''}»
if (''condition'') {''instructions''}<br/>elsif (''condition'') {''instructions''}<br/>''...''<br/>«else {''instructions''}»
or
unless (''notcondition'') {''instructions''}<br/>elsif (''condition'') {''instructions''}<br/>''...''<br/>«else {''instructions''}»
use feature "switch";<br/>''...''<br/>given (''variable'') { {{indent|2}}when (''case<sub>1</sub>'') { ''instructions'' }{{indent|2}}''...''{{indent|2}}«default { ''instructions'' }»<br/>}''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''
Rakuif ''condition'' {''instructions''}<br/>«else {''instructions''}»
or
unless ''notcondition'' {''instructions''}
if ''condition'' {''instructions''}<br/>elsif ''condition'' {''instructions''}<br/>...<br/>«else {''instructions''}given ''variable'' { {{indent|2}}when ''case<sub>1</sub>'' { ''instructions'' }{{indent|2}}''...''{{indent|2}}«default { ''instructions'' }»<br/>}''condition'' [[?:|??]] ''valueIfTrue'' !valueIfFalse
Rubyif ''condition''{{indent|2}}''instructions''<br/>«else{{indent|2}}''instructions»''if ''condition''{{indent|2}}''instructions''<br/>elsif ''condition''{{indent|2}}''instructions''<br/>''...''<br/>«else{{indent|2}}''instructions''»<br/>endcase ''variable''{{indent|2}}when ''case<sub>1</sub>''{{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}«else{{indent|4}}''instructions''»<br/>end''condition'' [[?:|?]] ''valueIfTrue'' [[?:|:]] ''valueIfFalse''
Scalaif (''condition'') {''instructions''}<br/>«else {''instructions''}»if (''condition'') {''instructions''}<br/>else if (''condition'') {''instructions''}<br/>...<br/>«else {''instructions''}»''expression'' match { {{indent|2}}case ''pattern1'' => ''expression''{{indent|2}}case ''pattern2'' => ''expression''{{indent|2}}''...''{{indent|2}}«case _ => ''expression''»<br/>}if (''condition'') ''valueIfTrue'' else ''valueIfFalse''
Smalltalk''condition'' ifTrue:{{indent|2}}''trueBlock''<br/>«ifFalse:{{indent|2}}''falseBlock''»<br/>end''condition'' ifTrue: ''trueBlock'' ifFalse: ''falseBlock''
Common Lisp''(when'' condition{{indent|2}}''instructions'')
or
(unless ''condition''{{indent|2}}''instructions'')
or
(if ''condition''{{indent|2}}(progn ''instructions''){{indent|2}}«(progn ''instructions'')»)
(cond (''condition1 instructions''){{indent|2}}(''condition2 instructions''){{indent|2}}''...''{{indent|2}}«(t ''instructions'')»)(case ''expression''{{indent|2}}(''case1 instructions''){{indent|2}}(''case2 instructions''){{indent|2}}''...''{{indent|2}}«(otherwise ''instructions'')»)(if ''test then else'')
or
(cond (''test1 value1'') (''test2 value2'') ''...''))
Scheme(when ''condition instructions'')
or
(if ''condition'' (begin ''instructions'') «(begin ''instructions'')»)
(cond (''condition1 instructions'') (''condition2 instructions'') ''...'' «(else ''instructions'')»)(case (''variable'') ((''case1'') ''instructions'') ((''case2'') ''instructions'') ''...'' «(else ''instructions'')»)(if ''condition valueIfTrue valueIfFalse'')
ISLISP(if ''condition''{{indent|2}}(progn ''instructions''){{indent|2}}«(progn ''instructions'')»)(cond (''condition1 instructions''){{indent|2}}(''condition2 instructions''){{indent|2}}''...''{{indent|2}}«(t ''instructions'')»)(case ''expression''{{indent|2}}(''case1 instructions''){{indent|2}}(''case2 instructions''){{indent|2}}''...''{{indent|2}}«(t ''instructions'')»)(if ''condition valueIfTrue valueIfFalse'')
Pascalif ''condition'' then begin{{indent|2}}''instructions''<br/>end<br/>«else begin{{indent|2}}''instructions''<br/>end»'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»case ''variable'' of{{indent|2}}''case1'': ''instructions''{{indent|2}}''...''{{indent|2}}«else: ''instructions''»<br/>end
Visual BasicIf ''condition'' Then{{indent|2}}''instructions''<br/>«Else{{indent|2}}''instructions''»<br/>End If
Single-line, when instructions are instruction{{sub|1}} : instruction{{sub|2}} : ...:
If ''condition'' Then ''instructions'' «Else ''instructions»''
If ''condition'' Then{{indent|2}}''instructions''<br/>ElseIf ''condition'' Then{{indent|2}}''instructions''<br/>''...''<br/>«Else{{indent|2}}''instructions''»<br/>End If
Single-line:
See note about C-like languages; the Else clause of a single-line If statement can contain another single-line If statement.
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[[IIf]](''condition'', ''valueIfTrue'', ''valueIfFalse'')
Visual Basic .NETIf(''condition'', ''valueIfTrue'', ''valueIfFalse'')
Xojo
Pythonif ''condition'' :<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''if ''condition'' :<br/>{{keypress|Tab}}''instructions''<br/>elif ''condition'' :<br/>{{keypress|Tab}}''instructions''<br/>''...''<br/>«else:<br/>{{keypress|Tab}}''instructions»''Python 3.10+:
match ''variable'':<br/>{{keypress|Tab}}case ''case1'':<br/>{{keypress|Tab}}{{keypress|Tab}}''instructions''<br/>{{keypress|Tab}}case ''case2'':<br/>{{keypress|Tab}}{{keypress|Tab}}''instructions''
Python 2.5+:
''valueIfTrue'' if ''condition'' else ''valueIfFalse''
S-Langif (''condition'') { ''instructions'' } «else { ''instructions'' }»if (''condition'') { ''instructions'' } else if (''condition'') { ''instructions'' } ''...'' «else { ''instructions'' }»switch (''variable'') { case ''case1'': ''instructions'' } { case ''case2'': ''instructions'' } ''...''
FortranIF (''condition'') THEN{{indent|2}}''instructions''<br/>ELSE{{indent|2}}''instructions''<br/>ENDIFIF (''condition'') THEN{{indent|2}}''instructions''<br/>ELSEIF (''condition'') THEN{{indent|2}}''instructions''<br/>''...''<br/>ELSE{{indent|2}}''instructions''<br/>ENDIFSELECT CASE(''variable''){{indent|2}}CASE (''case1''){{indent|4}}''instructions''{{indent|2}}''...''{{indent|2}}CASE DEFAULT{{indent|4}}''instructions''<br/>END SELECT
Forth''condition'' IF ''instructions'' « ELSE ''instructions''» THEN''condition'' IF ''instructions'' ELSE ''condition'' IF ''instructions'' THEN THEN''value'' CASE{{indent|2}}''case'' OF ''instructions'' ENDOF{{indent|2}}''case'' OF ''instructions'' ENDOF{{indent|4}}''default instructions''<br/>ENDCASE''condition'' IF ''valueIfTrue ''ELSE ''valueIfFalse'' THEN
OCamlif ''condition'' then begin ''instructions'' end «else begin ''instructions'' end»if ''condition'' then begin ''instructions'' end else if ''condition'' then begin ''instructions'' end ''...'' «else begin ''instructions'' end»match ''value'' with {{indent|2}}''pattern1'' -> ''expression''{{indent|2}}{{pipe}} ''pattern2'' -> ''expression''{{indent|2}}''...''{{indent|2}}«{{pipe}} _ -> ''expression''»if ''condition'' then ''valueIfTrue'' else ''valueIfFalse''
F#Lightweight syntax mode:Either on a single line or with indentation as shown below:if ''condition'' then<br/>{{keypress|Tab}}''instructions''<br/>«else<br/>{{keypress|Tab}}''instructions»''
Verbose syntax mode:
Same as Standard ML.
Lightweight syntax mode:
Either on a single line or with indentation as shown below:
if ''condition'' then<br/>{{keypress|Tab}}''instructions''<br/>elif ''condition'' then<br/>{{keypress|Tab}}''instructions''<br/>''...''<br/>«else<br/>{{keypress|Tab}}''instructions»''
Verbose syntax mode:
Same as Standard ML.
Standard MLif ''condition'' then «(''»instructions «'')»<br/>else «(''» instructions «'')»if ''condition'' then «(''»instructions «'')»<br/>else if ''condition'' then «(''» instructions «'')»<br/>''...''<br/>else «(''» instructions «'')»case ''value'' of{{indent|2}}''pattern1'' => ''expression''{{indent|2}}{{pipe}} ''pattern2'' => ''expression''{{indent|2}}''...''{{indent|2}}«{{pipe}} _ => ''expression»''
Haskell (GHC)if ''condition'' then ''expression'' else ''expression''
or
when ''condition'' (do ''instructions'')
or
unless ''notcondition'' (do ''instructions'')
''result'' {{pipe}} ''condition'' = ''expression''{{indent|2}}{{pipe}} ''condition'' = ''expression''{{indent|2}}{{pipe}} otherwise = ''expression''case ''value'' of { {{indent|2}}''pattern1'' -> ''expression'';{{indent|2}}''pattern2'' -> ''expression'';{{indent|2}}''...''{{indent|2}}«_ -> ''expression»''<br/>}
Bash shellif ''condition-command;'' then{{indent|2}}''expression''<br/>«else{{indent|2}}''expression''»<br/>fiif ''condition-command;'' then{{indent|2}}''expression''<br/>elif ''condition-command;'' then{{indent|2}}''expression''<br/>«else{{indent|2}}''expression''»<br/>ficase ''"$variable"'' in{{indent|2}}''"$condition1"){{indent|4}}command...{{indent|2}}"$condition2"){{indent|4}}command...''<br/>esac
CoffeeScriptif ''condition'' then ''expression'' «else ''expression»''
or
if ''condition{{indent|2}}expression''<br/>«else{{indent|2}}''expression»''
or
''expression'' if ''condition''
or
unless ''condition''{{indent|2}}''expression''<br/>«else{{indent|2}}''expression»''
or
''expression'' unless ''condition''
if ''condition'' then ''expression'' else if ''condition'' then ''expression'' «else ''expression»''
or
if ''condition''{{indent|2}}''expression''<br/>else if ''condition{{indent|2}}expression''<br/>«else{{indent|2}}''expression»''
or
unless ''condition''{{indent|2}}''expression''<br/>else unless ''condition{{indent|2}}expression''<br/>«else{{indent|2}}''expression»''
switch ''expression''{{indent|2}}when ''condition'' then ''expression''{{indent|2}}else ''expression''
or
switch ''expression''{{indent|2}}when ''condition''{{indent|4}}''expression''{{indent|2}}«else{{indent|4}}''expression»''
All conditions are expressions.
COBOLIF ''condition'' «THEN»{{indent|2}}''expression''<br/>«ELSE{{indent|2}}''expression»''.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
Rustif ''condition'' { {{indent|2}}''expression''<br/>}« else { {{indent|2}}''expression''<br/>}»if ''condition'' { {{indent|2}}''expression''<br/>} else if ''condition'' {''{{indent|2}}expression<br/>''}« else {''{{indent|2}}expression<br/>''}''»''match ''variable'' { {{indent|2}}''pattern1'' => ''expression,''{{indent|2}}''pattern2'' => ''expression,''{{indent|2}}''pattern3'' => ''expression,''{{indent|2}}«_ => ''expression''»<br/>}All conditions are expressions
ifelse ifselect caseconditional expression
  • A single instruction can be written on the same line following the colon. Multiple instructions are grouped together in a block which starts on a newline (The indentation is required). The conditional expression syntax does not follow this rule.
  • This is pattern matching and is similar to select case but not the same. It is usually used to deconstruct algebraic data types.
  • In languages of the Pascal family, the semicolon is not part of the statement. It is a separator between statements, not a terminator.
  • END-IF may be used instead of the period at the end.
  • In Rust, the comma (,) 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 {}).
while loopdo while loop(count-controlled) for loopforeach
Adawhile ''condition'' loop{{indent|2}}''statements''<br/>end looploop{{indent|2}}''statements''{{indent|2}}exit when not ''condition''<br/>end loopfor ''index'' in «reverse» ''[first'' .. ''last {{pipe}} discrete_type]'' loop{{indent|2}}''statements''<br/>end loopfor ''item'' of «reverse» ''iterator'' loop{{indent|2}}''statements''<br/>end loop
or
(for [all {{pipe}} some] [in {{pipe}} of] ''[first'' .. ''last {{pipe}} discrete_type {{pipe}} iterator]'' => ''predicate'')
«for ''index''» «from ''first''» «by ''increment''» «to ''last''» «while ''condition''» do ''statements'' odfor key «to upb list» do «typename val=list[key];» ''statements'' od
«while ''condition''»{{indent|2}}do ''statements'' od«while ''statements; condition''»{{indent|2}}do ''statements'' od«for ''index''» «from ''first''» «by ''increment''» «to ''last''» do ''statements'' od
APL:While ''condition''{{indent|2}}''statements''<br/>:EndWhile:Repeat{{indent|2}}''statements''<br/>:Until ''condition'':For ''var«s»'' :In ''list''{{indent|2}}''statements''<br/>:EndFor:For ''var«s»'' :InEach ''list''{{indent|2}}''statements''<br/>:EndFor
C (C99)instructions can be a single statement or a block in the form of: { ''statements'' }
while (''condition'') ''instructions''
do ''instructions'' while (''condition'');for (''«type» i'' = ''first''; ''i'' <= ''last''; ''i''++) ''instructions''
Objective-Cfor (''type item'' in ''set'') ''instructions''
C++ (STL)«std::»for_each(''start'', ''end'', ''function'')
Since C++11:
for (''type item'' : ''set'') ''instructions''
C#foreach (''type item'' in ''set'') ''instructions''
Javafor (''type item'' : ''set'') ''instructions''
JavaScriptfor (var ''i'' = ''first''; ''i'' <= ''last''; ''i''++) ''instructions''Since EcmaScript 2015:[11] for (var ''item'' of ''set'') ''instructions''
PHPforeach (range(''first'', ''last'') as $i) ''instructions''
or
for ($i = ''first''; $i <= ''last''; $i++) ''instructions''
foreach (''set'' as ''item'') ''instructions''
or
foreach (''set'' as ''key'' => ''item'') ''instructions''
Windows PowerShellfor ($i = ''first''; $i -le ''last''; $i++) ''instructions''foreach (''item'' in ''set'') ''instructions''
Dforeach ''(i;'' first ''...'' last) ''instructions''foreach ''(«type» item; set) instructions''
Gofor ''condition'' { ''instructions'' }for ''i'' := ''first''; ''i'' <= ''last''; ''i''++ { ''instructions'' }for ''key'', ''item'' := range ''set'' { ''instructions'' }
Swiftwhile ''condition'' { ''instructions'' }2.x:
repeat { ''instructions'' } while ''condition''
1.x:
do { ''instructions'' } while ''condition''
for ''i'' = ''first'' ... ''last'' { ''instructions'' }
or
for ''i'' = ''first'' ..< ''last+1'' { ''instructions'' }
or
for var ''i'' = ''first''; ''i'' <= ''last''; ''i''++ { ''instructions'' }
for ''item'' in ''set'' { ''instructions'' }
Perlwhile (''condition'') { ''instructions'' }
or
until (''notcondition'') { ''instructions'' }
do { ''instructions'' } while (''condition'')
or
do { ''instructions'' } until (''notcondition'')
for«each» «$i» (''first'' .. ''last'') { ''instructions'' }
or
for ($i = ''first''; $i <= ''last''; $i++) { ''instructions'' }
for«each» ''«$item»'' (''set'') { ''instructions'' }
Rakuwhile ''condition'' { ''instructions'' }
or
until ''notcondition'' { ''instructions'' }
repeat { ''instructions'' } while ''condition''
or
repeat { ''instructions'' } until ''notcondition''
for ''first''..''last'' -> $i { ''instructions'' }
or
loop ($i = ''first''; $i <=''last''; $i++) { ''instructions'' }
for ''set«'' -> ''$item»'' { ''instructions'' }
Rubywhile ''condition''{{indent|2}}''instructions''<br/>end
or
until ''notcondition''{{indent|2}}''instructions''<br/>end
begin{{indent|2}}''instructions''<br/>end while ''condition''
or
begin{{indent|2}}''instructions''<br/>end until ''notcondition''
for i in ''first''..''last''{{indent|2}}''instructions''<br/>end
or
for i in ''first''...''last+1''{{indent|2}}''instructions''<br/>end
or
''first''.{{not a typo|upto}}(''last'') { {{pipe}}i{{pipe}} ''instructions'' }
for ''item'' in ''set''{{indent|2}}''instructions''<br/>end
or
''set''.each { {{pipe}}''item''{{pipe}} ''instructions'' }
Bash shellwhile ''condition ;''do{{indent|2}}''instructions''<br/>done
or
until ''notcondition ;''do{{indent|2}}''instructions''<br/>done
for ((''i'' = ''first''; ''i'' <= ''last''; ++''i'')) ; do{{indent|2}}''instructions''<br/>donefor ''item'' in ''set ;''do{{indent|2}}''instructions''<br/>done
Scalawhile (''condition'') { ''instructions'' }do { ''instructions'' } while (''condition'')for (''i'' <- ''first'' to ''last'' «by 1») { ''instructions'' }
or
''first'' to ''last'' «by 1» foreach (''i'' => { ''instructions'' })
for (''item'' <- ''set'') { ''instructions'' }
or
''set'' foreach (''item'' => { ''instructions'' })
Smalltalk''conditionBlock'' whileTrue:{{indent|2}}''loopBlock''''loopBlock'' doWhile:{{indent|2}}''conditionBlock''''first'' to: ''last'' do:{{indent|2}}''loopBlock''''collection'' do:{{indent|2}}''loopBlock''
Common Lisp(loop{{indent|2}}while ''condition''{{indent|2}}do{{indent|2}}''instructions'')
or
(do (''notcondition''){{indent|2}}''instructions'')
(loop{{indent|2}}do{{indent|2}}''instructions''{{indent|2}}while ''condition'')(loop{{indent|2}}for i from ''first'' to ''last «by 1»''{{indent|2}}do{{indent|2}}''instructions'')
or
(dotimes (i N){{indent|2}}''instructions'')
or
(do ((i ''first'' (1+ i))) ((>=i ''last''))<br/>{{indent|2}}''instructions'')
(loop{{indent|2}}for ''item'' in ''list''{{indent|2}}do{{indent|2}}''instructions'')
or
(loop{{indent|2}}for ''item'' across ''vector''{{indent|2}}do{{indent|2}}''instructions'')
or
(dolist (''item list''){{indent|2}}''instructions'')
or
(mapc ''function list'')
or
(map ''type function sequence'')
Scheme(do (''notcondition'') ''instructions'')
or
(let loop (if ''condition'' (begin ''instructions'' (loop))))
(let loop (''instructions'' (if ''condition'' (loop))))(do ((i ''first'' (+ i 1))) ((>= i ''last'')) ''instructions'')
or
(let loop ((i ''first'')) (if (< i ''last'') (begin ''instructions'' (loop (+ i 1)))))
(for-each (lambda (''item'') ''instructions'') ''list'')
ISLISP(while ''condition instructions'')(tagbody loop ''instructions'' (if ''condition'' (go loop))(for ((i ''first'' (+ i 1))) ((>= i ''last'')) ''instructions'')(mapc (lambda (''item'') ''instructions'') ''list'')
Pascalwhile ''condition'' do begin{{indent|2}}''instructions''<br/>endrepeat{{indent|2}}''instructions''<br/>until ''notcondition'';for ''i'' := ''first'' «step 1» to ''last'' do begin{{indent|2}}''instructions''<br/>end;for ''item'' in ''set'' do ''instructions''
Visual BasicDo While ''condition''{{indent|2}}''instructions''<br/>Loop
or
Do Until ''notcondition''{{indent|2}}''instructions''<br/>Loop
or
While ''condition''{{indent|2}}''instructions''<br/>Wend (Visual Basic .NET uses End While instead)
Do{{indent|2}}''instructions''<br/>Loop While ''condition''
or
Do{{indent|2}}''instructions''<br/>Loop Until ''notcondition''
i must be declared beforehand.For ''i'' = ''first'' To ''last'' «Step ''1»{{indent|2}}instructions''<br/>Next iFor Each ''item'' In ''set''{{indent|2}}''instructions''<br/>Next ''item''
Visual Basic .NETFor i« As ''type»'' = ''first'' To ''last«'' Step ''1»{{indent|2}}instructions''<br/>Next« i»For Each ''item«'' As ''type»'' In ''set''{{indent|2}}''instructions''<br/>Next''« item»''
XojoWhile ''condition''{{indent|2}}''instructions''<br/>WendDo Until ''notcondition''{{indent|2}}''instructions''<br/>Loop
or
Do{{indent|2}}''instructions''<br/>Loop Until ''notcondition''
Pythonwhile ''condition'' :<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''Python 3.x:
for i in range(''first'', ''last+1''):<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''
Python 2.x:
for i in xrange(''first'', ''last+1''):<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''
for ''item'' in ''set'':<br/>{{keypress|Tab}}''instructions''<br/>«else:<br/>{{keypress|Tab}}''instructions»''
S-Langwhile (''condition'') { ''instructions'' } «then ''optional-block»''do { ''instructions'' } while (''condition'') «then ''optional-block»''for (i = ''first''; i <= ''last''; i++) { ''instructions'' } «then ''optional-block»''foreach ''item''(''set'') «using (''what'')» { ''instructions'' } «then ''optional-block»''
FortranDO WHILE (''condition''){{indent|2}}''instructions''<br/>ENDDODO{{indent|2}}''instructions''{{indent|2}}IF (''condition'') EXIT<br/>ENDDODO ''I'' = ''first'',''last''{{indent|2}}''instructions''<br/>ENDDO
ForthBEGIN ''«instructions» condition'' WHILE ''instructions'' REPEATBEGIN '' instructions condition'' UNTIL''limit start'' DO ''instructions'' LOOP
OCamlwhile ''condition'' do ''instructions'' donefor i = ''first'' to ''last'' do ''instructions'' doneArray.iter (fun ''item'' -> ''instructions'') ''array''
or
List.iter (fun ''item'' -> ''instructions'') ''list''
F#while ''condition'' do<br/>{{keypress|Tab}}''instructions''for i = ''first'' to ''last'' do<br/>{{keypress|Tab}}''instructions''for''item'' in ''set'' do<br/>{{keypress|Tab}}''instructions''
or
Seq.iter (fun ''item'' -> ''instructions'') ''set''
Standard MLwhile ''condition'' do (''instructions'')Array.app (fn ''item'' => ''instructions'') ''array''
or
app (fn ''item'' => ''instructions'') ''list''
Haskell (GHC)Control.Monad.forM_ [''first''..''last''] (\i -> do ''instructions'')Control.Monad.forM_''list'' (\item -> do ''instructions'')
Eiffelfrom{{indent|2}}''setup''<br/>until{{indent|2}}''condition''<br/>loop{{indent|2}}''instructions''<br/>end
CoffeeScriptwhile ''condition''{{indent|2}}''expression''
or
''expression'' while ''condition''
or
while ''condition'' then ''expression''
or
until ''condition''{{indent|2}}''expression''
or
''expression'' until ''condition''
or
until ''expression'' then ''condition''
for ''i'' in [''first''..''last'']{{indent|2}}''expression''
or
for ''i'' in [''first''..''last''] then ''expression''
or
''expression'' for ''i'' in [''first''..''last'']
for ''item'' in ''set''{{indent|2}}''expression''
or
for ''item'' in ''set'' then ''expression''
or
''expression'' for ''item'' in ''set''
COBOLPERFORM ''procedure-1'' «THROUGH ''procedure-2''» ««WITH» TEST BEFORE» UNTIL ''condition''
or
PERFORM ««WITH» TEST BEFORE» UNTIL ''condition''{{indent|2}}''expression''<br/>END-PERFORM
PERFORM ''procedure-1'' «THROUGH ''procedure-2''» «WITH» TEST AFTER UNTIL ''condition''
or
PERFORM «WITH» TEST AFTER UNTIL ''condition''{{indent|2}}''expression''<br/>END-PERFORM
PERFORM ''procedure-1'' «THROUGH ''procedure-2»'' VARYING ''i'' FROM ''first'' BY ''increment'' UNTIL ''i'' > ''last''
or
PERFORM VARYING ''i'' FROM ''first'' BY ''increment'' UNTIL ''i'' > ''last''{{indent|2}}''expression''<br/>END-PERFORM
Rustwhile ''condition'' { {{indent|2}}''expression''<br/>}loop { {{indent|2}}''expression''{{indent|4}}if ''condition'' { {{indent|6}}break;{{indent|2}}}<br/>}for i in ''first''..''last+1'' { {{indent|2}}''expression''<br/>}
or
for i in ''first''..=''last'' { {{indent|2}}''expression''<br/>}
for ''item'' in ''set'' { {{indent|2}}''expression''<br/>}
or
''set''.into_iter.for_each({{pipe}}''item''{{pipe}} expression);
  • "step n" is used to change the loop interval. If "step" is omitted, then the loop interval is 1.
  • This implements the universal quantifier ("for all" or "

\forall

") as well as the existential quantifier ("there exists" or "

\exists

").
  • THRU may be used instead of THROUGH.
  • «IS» GREATER «THAN» may be used instead of >.
  • Type of set expression must implement trait std::iter::IntoIterator.

Notes and References

  1. Ada Reference Manual – Language and Standard Libraries; ISO/IEC 8652:201x (E), Web site: Reference Manual . 2013-07-19 . dead . https://web.archive.org/web/20110427190723/http://www.ada-auth.org/standards/12rm/RM-Final.pdf . 2011-04-27 .
  2. Web site: Common Lisp HyperSpec (TM). lispworks.com. 30 January 2017.
  3. Web site: www.islisp.info: Specification. islisp.info. 30 January 2017. https://web.archive.org/web/20160122121427/http://islisp.info/specification.html. 22 January 2016. dead.
  4. Web site: selected_int_kind in Fortran Wiki. fortranwiki.org. 30 January 2017.
  5. Web site: Erlang Types and Function Specifications. erlang.org. 30 January 2017.
  6. Web site: Erlang Advanced. erlang.org. 30 January 2017.
  7. https://www.mozilla.org/js/language/E262-3.pdf 8.5 The Number Type
  8. Web site: selected_real_kind in Fortran Wiki. fortranwiki.org. 30 January 2017.
  9. Web site: The GNU C Library: Complex Numbers. gnu.org. 30 January 2017.
  10. Web site: Grammar vb. 2016-06-17. Visual Basic Language Specification. https://web.archive.org/web/20190829225051/https://ljw1004.github.io/vbspec/vb.html. 2019-08-29. live. 2019-08-29.
  11. Web site: for...of. mozilla.org. 30 January 2017.
  12. Web site: Try-Catch for VB. google.com. 30 January 2017. 16 April 2016. https://web.archive.org/web/20160416093023/https://sites.google.com/site/truetryforvisualbasic/. dead.
  13. Book: Klabnik . Steve . Nichols . Carol . The Rust Programming Language . Error Handling. https://doc.rust-lang.org/book/ch09-00-error-handling.html.
  14. Web site: Prime decomposition – Rosetta Code. rosettacode.org. 30 January 2017.
  15. Web site: iso_fortran_env in Fortran Wiki. fortranwiki.org. 30 January 2017.
  16. Web site: Execute a system command – Rosetta Code. rosettacode.org. 30 January 2017.
  17. Web site: EXECUTE_COMMAND_LINE – The GNU Fortran Compiler. gnu.org. 30 January 2017.