Английская Википедия:Comparison of programming languages (basic instructions)
Шаблон:Short description Шаблон:Refimprove Шаблон:ProgLangCompare 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.
Conventions of this article
Generally, var, Шаблон:Var, or Шаблон:Var serif is how variable names or other non-literal values to be interpreted by the reader are represented. The rest is literal code. Guillemets (Шаблон:Code and Шаблон:Code) enclose optional sections. Шаблон:Keypress 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
- Шаблон:Note The standard constants Шаблон:Code and Шаблон:Code can be used to determine how many Шаблон:Codes and Шаблон:Codes can be usefully prefixed to Шаблон:Code and Шаблон:Code. The actual sizes of Шаблон:Code, Шаблон:Code, and Шаблон:Code are available as the constants Шаблон:Code, Шаблон:Code, and Шаблон:Code etc.
- Шаблон:Note Commonly used for characters.
- Шаблон:Note The ALGOL 68, C and C++ languages do not specify the exact width of the integer types Шаблон:Code, Шаблон:Code, Шаблон:Code, and (C99, C++11) Шаблон:Code, so they are implementation-dependent. In C and C++ Шаблон:Code, Шаблон:Code, and Шаблон:Code types are required to be at least 16, 32, and 64 bits wide, respectively, but can be more. The Шаблон:Code type is required to be at least as wide as Шаблон:Code and at most as wide as Шаблон: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 also define the Шаблон:Code exact-width types in the stdint.h header. See C syntax#Integral types for more information. In addition the types Шаблон:Code and Шаблон: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 Perl 5 does not have distinct types. Integers, floating point numbers, strings, etc. are all considered "scalars".
- Шаблон:Note PHP has two arbitrary-precision libraries. The BCMath library just uses strings as datatype. The GMP library uses an internal "resource" type.
- Шаблон:Note The value of Шаблон:Code is provided by the Шаблон:Code[4] intrinsic function.
- Шаблон:Note ALGOL 68G's runtime option Шаблон:Code can set precision for Шаблон:Codes to the required "number" significant digits. The standard constants Шаблон:Code and Шаблон:Code can be used to determine actual precision.
- Шаблон:Note COBOL allows the specification of a required precision and will automatically select an available type capable of representing the specified precision. "Шаблон: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 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) and one supporting arbitrary sized integers (Шаблон:Mono). Arithmetic operations support polymorphic arguments and return the result in the most appropriate compact representation.
- Шаблон:Note 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
). Шаблон:Code (8 bits), Шаблон:Code (16 bits) and Шаблон: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 modulo types implement modulo arithmetic in all operations, i.e. no range violations are possible. Modulos are not restricted to powers of two.
- Шаблон:Note Commonly used for characters like Java's char.
- Шаблон:Note Шаблон:Code in PHP has the same width as Шаблон:Code type in C has on that system.Шаблон:Ref
- Шаблон:Note 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]
- Шаблон:Note When it exceeds one word.[6]
Floating point
- Шаблон:Note The standard constants Шаблон:Code and Шаблон:Code can be used to determine how many Шаблон:Codes and Шаблон:Codes can be usefully prefixed to Шаблон:Code and Шаблон:Code. The actual sizes of Шаблон:Code, Шаблон:Code, and Шаблон:Code are available as the constants Шаблон:Code, Шаблон:Code and Шаблон:Code etc. With the constants Шаблон:Code, Шаблон:Code and Шаблон:Code available for each type's machine epsilon.
- Шаблон:Note declarations of single precision often are not honored
- Шаблон:Note The value of Шаблон:Code is provided by the Шаблон:Code[8] intrinsic function.
- Шаблон:Note ALGOL 68G's runtime option Шаблон:Code can set precision for Шаблон:Codes to the required "number" significant digits. The standard constants Шаблон:Code and Шаблон:Code can be used to determine actual precision.
- Шаблон:Note These IEEE floating-point types will be introduced in the next COBOL standard.
- Шаблон:Note Same size as Шаблон:Code on many implementations.
- Шаблон:Note Swift supports 80-bit extended precision floating point type, equivalent to Шаблон:Code in C languages.
Complex numbers
- Шаблон:Note The value of Шаблон:Code is provided by the Шаблон:Code[8] intrinsic function.
- Шаблон:Note Generic type which can be instantiated with any base floating point type.
Other variable types
- Шаблон:Note specifically, strings of arbitrary length and automatically managed.
- Шаблон:Note 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 All values evaluate to either true or false. Everything in Шаблон:Code evaluates to true and everything in Шаблон:Code evaluates to false.
- Шаблон:NoteThis language does not have a separate character type. Characters are represented as strings of length 1.
- Шаблон:Note Enumerations in this language are algebraic types with only nullary constructors
- Шаблон:Note The value of Шаблон:Code is provided by the Шаблон:Code[4] intrinsic function.
Derived types
Array
fixed size array | dynamic size array | |||
---|---|---|---|---|
one-dimensional array | multidimensional array | one-dimensional array | multidimensional array | |
Ada[1] | array (<first> .. <last>) of <type> or array (<discrete_type>) of <type>
|
array (<first1> .. <last1>, <first2> .. <last2>, ...) of <type> or array (<discrete_type1>, <discrete_type2>, ...) of <type>
|
array (<discrete_type> range <>) of <type>
|
array (<discrete_type1> range <>, <discrete_type2> range <>, ...) of <type>
|
ALGOL 68 | [first:last] or simply: [size]
|
[first1:last1, first2:last2] or [first1:last1][first2:last2] etc. |
flex[first:last] or simply: flex[size]
|
flex[first1:last1, first2:last2] or flex[first1:last1]
|
C (C99) | type name[size] Шаблон:Ref
|
type name[size1][size2] Шаблон:Ref
|
type *name or within a block: int n = ...; type name[n]
|
|
C++ (STL) | «std::»array<type, size> (C++11)
|
«std::»vector<type>
| ||
C# | type[]
|
type[[[:Шаблон:Not a typo]]...]
|
System or System
|
|
Java | type[] Шаблон:Ref
|
type[][]... Шаблон:Ref
|
ArrayList or ArrayList<type>
|
|
D | type[size]
|
type[size1][size2]
|
type[]
|
|
Go | [size]type
|
[size1][size2]...type
|
[]type
|
[][]type
|
Rust | [type; size]
|
[[type; size1]; size2]
|
Vec<type>
|
Vec<Vec<type>>
|
Swift | [type] or Array<type>
|
[[type]] or Array<Array<type>>
| ||
Objective-C | NSArray
|
NSMutableArray
|
||
JavaScript | Шаблон:N/a | Шаблон:N/a | Array Шаблон:Ref
| |
Common Lisp | Шаблон:Code | Шаблон:Code | Шаблон:Code | Шаблон:Code |
Scheme | ||||
ISLISP | ||||
Pascal | array[first..last] of type Шаблон:Ref
|
array[first1..last1] of array[first2..last2] ... of type Шаблон:Refor array[first1..last1, first2..last2, ...] of type Шаблон:Ref
|
Шаблон:N/a | Шаблон:N/a |
Object Pascal (Delphi) | array of type
|
array of array ... of type
| ||
Visual Basic | Dim x(last) As type
|
Dim x(last1, last2,...) As type
|
||
Visual Basic .NET | type()
|
type(Шаблон:Not a typo...)
|
System or System
|
|
Python | list
|
|||
S-Lang | x = type[size];
|
x = type[size1, size2, ...];
|
||
Fortran | type :: name(size)
|
type :: name(size1, size2,...)
|
type, ALLOCATABLE :: name(:)
|
type, ALLOCATABLE :: name(:,:,...)
|
PHP | array
|
|||
Perl | ||||
Raku | Array[type] or Array of type
|
|||
Ruby | x = Array.new(size1){ Array.new(size2) }
|
Array
|
||
Scala | Array[type]
|
Array[...[Array[type]]...]
|
ArrayBuffer[type]
|
|
Seed7 | array 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
|
Smalltalk | Array
|
OrderedCollection
|
||
Windows PowerShell | type[]
|
type[[[:Шаблон:Not a typo]]...]
|
||
OCaml | type array
|
type array ... array
|
||
F# | type [] or type array
|
type [[[:Шаблон:Not a typo]]...]
|
System or System
|
|
Standard ML | type vector or type array
|
|||
Haskell (GHC) | x = Array.array (0, size-1) list_of_association_pairs
|
x = Array.array ((0, 0,...), (size1-1, size2-1,...)) list_of_association_pairs
|
||
COBOL | level-number type OCCURS size «TIMES».
|
Шаблон:Em | level-number type OCCURS min-size TO max-size «TIMES» DEPENDING «ON» size. Шаблон:Ref
|
Шаблон:N/a |
- Шаблон:NoteIn most expressions (except the
sizeof
and Шаблон: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 The C-like
type x[]
works in Java, howevertype[] x
is the preferred form of array declaration. - Шаблон:Note Subranges are used to define the bounds of the array.
- Шаблон:Note JavaScript's array are a special kind of object.
- Шаблон:Note The Шаблон:Code 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 types | Algebraic data types | Unions | ||
---|---|---|---|---|
Records | Tuple expression | |||
Ada[1] | type name is «abstract» «tagged» «limited» [recordШаблон:IndentfieldШаблон:Sub : type;Шаблон:IndentfieldШаблон:Sub : type;Шаблон:Indent...
|
Шаблон:N/a | Any combination of records, unions, and enumerations (as well as references to those, enabling recursive types). | type name (variation : discrete_type) is recordШаблон:Indentcase variation isШаблон:Indentwhen choice_listШаблон:Sub =>Шаблон:IndentfieldnameШаблон:Sub : type;Шаблон:Indent...Шаблон:Indentwhen choice_listШаблон:Sub =>Шаблон:IndentfieldnameШаблон:Sub : type;Шаблон:Indent...Шаблон:Indent...Шаблон:Indentend case;
|
ALGOL 68 | struct (modename «fieldname», ...);
|
Required types and operators can be user-defined | union (modename, ...);
| |
C (C99) | struct «name» {type name;...};
|
rowspan=2 Шаблон:N/a | rowspan=3 Шаблон:N/a | union {type name;...};
|
Objective-C | ||||
C++ | struct «name» {type name;...}; Шаблон:Ref
|
«std::»tuple<typeШаблон:Sub..typeШаблон:Sub>
| ||
C# | struct name {type name;...}
|
(valШаблон:Sub, valШаблон:Sub, ... )
|
rowspan=3 Шаблон:N/a | |
Java | Шаблон:N/aШаблон:Ref | |||
JavaScript | Шаблон:N/a | |||
D | struct name {type name;...}
|
std.variant.Algebraic!(type,...)
|
union {type name;...}
| |
Go | struct { Шаблон:Indent«name» typeШаблон:Indent...
|
|||
Rust | struct name {name: type, ...}
|
(valШаблон:Sub, valШаблон:Sub, ... )
|
enum name { Foo(types), ...}
|
union name {name: type, ...}
|
Swift | struct name {Шаблон:Indentvar name «: type»Шаблон:Indent...
|
(«nameШаблон:Sub:» valШаблон:Sub, «nameШаблон:Sub:» valШаблон:Sub, «nameШаблон:Sub:» valШаблон:Sub, ... )
|
enum name { case Foo«(types)» case Bar «(types)» ... }
|
|
Common Lisp | Шаблон:Code | (cons valШаблон:Sub valШаблон:Sub) Шаблон:Ref
|
||
Scheme | Шаблон:N/a | |||
ISLISP | ||||
Pascal | recordШаблон:Indentname: type;Шаблон:Indent...
|
Шаблон:N/a | Шаблон:N/a | recordШаблон:Indentcase type ofШаблон:Indentvalue: (types);Шаблон:Indent...
|
Visual Basic | ||||
Visual Basic .NET | Structure nameШаблон:IndentDim name As typeШаблон:Indent...
|
(valШаблон:Sub, valШаблон:Sub, ... )
|
||
Python | Шаблон:N/aШаблон:Ref | «(»valШаблон:Sub, valШаблон:Sub, valШаблон:Sub, ... «)»
|
Шаблон:N/a | |
S-Lang | struct {name [=value], ...}
|
|||
Fortran | TYPE nameШаблон:Indenttype :: nameШаблон:Indent...
|
|||
PHP | Шаблон:N/aШаблон:Ref | |||
Perl | Шаблон:N/aШаблон:Ref | rowspan=3 Шаблон:N/a | ||
Raku | Шаблон:N/aШаблон:Ref | |||
Ruby | Шаблон:Code | |||
Scala | case class name(«var» name: type, ...)
|
(valШаблон:Sub, valШаблон:Sub, valШаблон:Sub, ... )
|
abstract class nameШаблон:Indentcase class Foo(«parameters») extends nameШаблон:Indentcase class Bar(«parameters») extends nameШаблон:Indent... or abstract class nameШаблон:Indentcase object Foo extends nameШаблон:Indentcase object Bar extends nameШаблон:Indent... or a combination of case classes and case objects |
|
Windows PowerShell | ||||
OCaml | type name = {«mutable» name : type;...}
|
«(»valШаблон:Sub, valШаблон:Sub, valШаблон:Sub, ... «)»
|
type name = Foo «of type» Шаблон:Pipe Bar «of type» Шаблон:Pipe ...
|
rowspan=4 Шаблон:N/a |
F# | ||||
Standard ML | type name = {name : type,...}
|
(valШаблон:Sub, valШаблон:Sub, valШаблон:Sub, ... )
|
datatype name = Foo «of type» Шаблон:Pipe Bar «of type» Шаблон:Pipe ...
| |
Haskell | data Name = Constr {name :: type,...}
|
data Name = Foo «types» Шаблон:Pipe Bar «types» Шаблон:Pipe ...
| ||
COBOL | level-number name type clauses.Шаблон:Indentlevel-number+n name type clauses.Шаблон:Indent...
|
Шаблон:N/a | Шаблон:N/a | name REDEFINES variable type.
|
- Шаблон:Note Only classes are supported.
- Шаблон:Note Шаблон:Codes 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.
- Шаблон:Note pair only
- Шаблон:Note 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 Enumerations in this language are algebraic types with only nullary constructors
Variable and constant declarations
variable | constant | type synonym | |
---|---|---|---|
Ada[1] | identifier : type« := initial_value» Шаблон:Ref
|
identifier : constant type := final_value
|
subtype identifier is type
|
ALGOL 68 | modename name« := initial_value»;
|
modename name = value;
|
mode synonym = modename;
|
C (C99) | type name« = initial_value»;
|
enum{ name = value };
|
typedef type synonym;
|
Objective-C | |||
C++ | const type name = value;
| ||
C# | type name1« = initial_value», name2« = 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 Шаблон:N/a |
JavaScript | var name« = initial_value»; orlet name« = initial_value»; (since ECMAScript 2015)
|
const name = value; (since ECMAScript 2015)
| |
Go | var name type« = initial_value» or name := initial_value
|
const name «type» = value
|
type synonym type
|
RustШаблон:Ref | let 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;
|
Swift | var 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 () 'type)
|
Scheme | (define name initial_value)
|
||
ISLISP | (defglobal name initial_value) or (defdynamic name initial_value)
|
(defconstant name value)
|
Шаблон:N/a |
PascalШаблон:Ref | name: type« = initial_value»
|
name = value
|
synonym = type
|
Visual Basic | Dim name «As type»
|
See notes to left.
Constants use the same syntax, and:
|
|
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"):
and that
valid declaration statements are of the form
Шаблон:In5
and for which, for each Шаблон:Code,
If Шаблон:Code is off, variables do not require explicit declaration; they are declared implicitly when used: Шаблон:Code |
Imports synonym = type
| |
Xojo | Dim name «As type»« = initial_value»
|
Шаблон:N/a | |
Python | name«: type» = initial_value
|
rowspan=2 Шаблон:N/a | synonym = type Шаблон:Ref
|
CoffeeScript | 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);
|
rowspan=2 Шаблон:N/a |
Perl | «my» $name« = initial_value»; Шаблон:Ref
|
use constant name => value;
| |
Raku | «my «type»» $name« = initial_value»; Шаблон:Ref
|
«my «type»» constant name = value;
|
::synonym ::= type
|
Ruby | name = initial_value
|
Name = value
|
synonym = type Шаблон:Ref
|
Scala | var name«: type» = initial_value
|
val name«: type» = value
|
type synonym = type
|
Windows PowerShell | «[type]» $name = initial_value
|
Шаблон:N/a | Шаблон:N/a |
Bash shell | name=initial_value
|
Шаблон:N/a | Шаблон:N/a |
OCaml | let name« : type ref» = ref value Шаблон:Ref
|
let name «: type» = value
|
type synonym = type
|
F# | let mutable name «: type» = value
| ||
Standard ML | val name «: type ref» = ref value Шаблон:Ref
|
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
|
Шаблон:N/a | Шаблон:N/a |
- Шаблон:Note Pascal has declaration blocks. See functions.
- Шаблон:NoteTypes are just regular objects, so you can just assign them.
- Шаблон:Note In Perl, the "my" keyword scopes the variable into the block.
- Шаблон:Note 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 and Шаблон:Code operators, respectively.
- Шаблон:Note 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 In Rust, if no initial value is given to a Шаблон:Code or Шаблон:Code variable and it is never assigned to later, there is an "unused variable" warning. If no value is provided for a Шаблон:Code or Шаблон:Code or Шаблон:Code variable, there is an error. There is a "non-upper-case globals" error for non-uppercase Шаблон:Code variables. After it is defined, a Шаблон:Code variable can only be assigned to in an Шаблон:Code block or function.
Control flow
Conditional statements
if | else if | select case | conditional expression | |
---|---|---|---|---|
Ada[1] | if condition thenШаблон:Indentstatements
|
if conditionШаблон:Sub thenШаблон:Indentstatements
|
case expression isШаблон:Indentwhen value_listШаблон:Sub => statementsШаблон:Indentwhen value_listШаблон:Sub => statementsШаблон:Indent...Шаблон:Indent«when others => statements»
|
(if conditionШаблон:Sub thenШаблон:IndentexpressionШаблон:Sub or (case expression isШаблон:Indentwhen value_listШаблон:Sub => expressionШаблон:SubШаблон:Indentwhen value_listШаблон:Sub => expressionШаблон:SubШаблон:Indent...Шаблон:Indent«when others => expressionШаблон:Sub»
|
Seed7 | if condition thenШаблон:Indentstatements
|
if conditionШаблон:Sub thenШаблон:Indentstatements
|
case expression ofШаблон:Indentwhen set1 : statementsШаблон:Indent...Шаблон:Indent«otherwise: statements»
|
|
Modula-2 | if condition thenШаблон:Indentstatements
|
if conditionШаблон:Sub thenШаблон:Indentstatements
|
case expression ofШаблон:IndentcaseLabelList : statements Шаблон:PipeШаблон:Indent...Шаблон:Indent«else statements»
|
|
ALGOL 68 | if condition then statements «else statements» fi
|
if condition then statements elif condition then statements fi
|
case 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Шаблон:Indentinstructions
|
:If conditionШаблон:Indentinstructions
|
:Select expressionШаблон:Indent:Case case1Шаблон:IndentinstructionsШаблон:Indent...Шаблон:Indent«:ElseШаблон:Indentinstructions»
|
{condition:valueIfTrue ⋄ valueIfFalse}
|
C (C99) | if (condition) instructions Шаблон:Code can be a single statement or a block in the form of: { statements }
|
if (condition) instructions or if (condition) instructions
|
switch (variable) { Шаблон:Indentcase case1: instructions «; break;»Шаблон:Indent...Шаблон:Indent«default: instructions»
|
condition ? valueIfTrue : valueIfFalse
|
Objective-C | ||||
C++ (STL) | ||||
D | ||||
Java | ||||
JavaScript | ||||
PHP | ||||
C# | if (condition) instructions
Шаблон:Code can be a single statement or a block in the form of: |
if (condition) instructions
|
switch (variable)
All non-empty cases must end with a Шаблон:Code or Шаблон:Code statement (that is, they are not allowed to fall-through to the next case). The Шаблон:Code case is not required to come last. |
condition ? valueIfTrue : valueIfFalse
|
Windows PowerShell | if (condition) instruction
|
if (condition) { instructions }
|
switch (variable) { case1{instructions «break;» } ... «default { instructions }»}
|
|
Go | if condition {instructions}
|
if condition {instructions} or switch { Шаблон:Indentcase condition: instructionsШаблон:Indent...Шаблон:Indent«default: instructions»
|
switch variable { Шаблон:Indentcase case1: instructionsШаблон:Indent...Шаблон:Indent«default: instructions»
|
|
Swift | if condition {instructions}
|
if condition {instructions}
|
switch variable { Шаблон:Indentcase case1: instructionsШаблон:Indent...Шаблон:Indent«default: instructions»
|
|
Perl | if (condition) {instructions} or unless (notcondition) {instructions}
|
if (condition) {instructions} or unless (notcondition) {instructions}
|
use feature "switch";
|
condition ? valueIfTrue : valueIfFalse
|
Raku | if condition {instructions} or unless notcondition {instructions}
|
if condition {instructions}
|
given variable { Шаблон:Indentwhen case1 { instructions }Шаблон:Indent...Шаблон:Indent«default { instructions }»
|
condition ?? valueIfTrue !! valueIfFalse
|
Ruby | if conditionШаблон:Indentinstructions
|
if conditionШаблон:Indentinstructions
|
case variableШаблон:Indentwhen case1Шаблон:IndentinstructionsШаблон:Indent...Шаблон:Indent«elseШаблон:Indentinstructions»
|
condition ? valueIfTrue : valueIfFalse
|
Scala | if (condition) {instructions}
|
if (condition) {instructions}
|
expression match { Шаблон:Indentcase pattern1 => expressionШаблон:Indentcase pattern2 => expressionШаблон:Indent...Шаблон:Indent«case _ => expression» Шаблон:Ref
|
if (condition) valueIfTrue else valueIfFalse
|
Smalltalk | condition ifTrue:Шаблон:IndenttrueBlock
|
condition ifTrue: trueBlock ifFalse: falseBlock
| ||
Common Lisp | (when conditionШаблон:Indentinstructions) or (unless conditionШаблон:Indentinstructions) or (if conditionШаблон:Indent(progn instructions)Шаблон:Indent«(progn instructions)»)
|
(cond (condition1 instructions)Шаблон:Indent(condition2 instructions)Шаблон:Indent...Шаблон:Indent«(t instructions)»)
|
(case expressionШаблон:Indent(case1 instructions)Шаблон:Indent(case2 instructions)Шаблон:Indent...Шаблон:Indent«(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(progn instructions)Шаблон:Indent«(progn instructions)»)
|
(cond (condition1 instructions)Шаблон:Indent(condition2 instructions)Шаблон:Indent...Шаблон:Indent«(t instructions)»)
|
(case expressionШаблон:Indent(case1 instructions)Шаблон:Indent(case2 instructions)Шаблон:Indent...Шаблон:Indent«(t instructions)»)
|
(if condition valueIfTrue valueIfFalse)
|
Pascal | if condition then beginШаблон:Indentinstructions Шаблон:Ref
|
if condition then beginШаблон:Indentinstructions Шаблон:Ref
|
case variable ofШаблон:Indentcase1: instructionsШаблон:Indent...Шаблон:Indent«else: instructions» Шаблон:Ref
| |
Visual Basic | If condition ThenШаблон:Indentinstructions Single-line, when Шаблон:Code are instructionШаблон:Sub : instructionШаблон:Sub : ... :If condition Then instructions «Else instructions»
|
If condition ThenШаблон:Indentinstructions Single-line: See note about C-like languages; the Шаблон:Code clause of a single-line Шаблон:Code statement can contain another single-line Шаблон:Code statement. |
Select« Case» variableШаблон:IndentCase case_patternШаблон:SubШаблон:IndentinstructionsШаблон:Indent...Шаблон:Indent«Case ElseШаблон:Indentinstructions»
|
IIf(condition, valueIfTrue, valueIfFalse)
|
Visual Basic .NET | If(condition, valueIfTrue, valueIfFalse)
| |||
Xojo | ||||
PythonШаблон:Ref | if condition :
|
if condition :
|
Python 3.10+:match variable:
|
Python 2.5+:valueIfTrue if condition else valueIfFalse
|
S-Lang | if (condition) { instructions } «else { instructions }»
|
if (condition) { instructions } else if (condition) { instructions } ... «else { instructions }»
|
switch (variable) { case case1: instructions } { case case2: instructions } ...
|
|
Fortran | IF (condition) THENШаблон:Indentinstructions
|
IF (condition) THENШаблон:Indentinstructions
|
SELECT CASE(variable)Шаблон:IndentCASE (case1)Шаблон:IndentinstructionsШаблон:Indent...Шаблон:IndentCASE DEFAULTШаблон:Indentinstructions
|
|
Forth | condition IF instructions « ELSE instructions» THEN
|
condition IF instructions ELSE condition IF instructions THEN THEN
|
value CASEШаблон:Indentcase OF instructions ENDOFШаблон:Indentcase OF instructions ENDOFШаблон:Indentdefault instructions
|
condition IF valueIfTrue ELSE valueIfFalse THEN
|
OCaml | if 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 Шаблон:Indentpattern1 -> expressionШаблон:IndentШаблон:Pipe pattern2 -> expressionШаблон:Indent...Шаблон:Indent«Шаблон:Pipe _ -> expression» Шаблон:Ref
|
if condition then valueIfTrue else valueIfFalse
|
F# | Lightweight syntax mode:
Either on a single line or with indentation as shown below:
|
Lightweight syntax mode: Either on a single line or with indentation as shown below: if condition then Verbose syntax mode: Same as Standard ML. | ||
Standard ML | if condition then «(»instructions «)»
|
if condition then «(»instructions «)»
|
case value ofШаблон:Indentpattern1 => expressionШаблон:IndentШаблон:Pipe pattern2 => expressionШаблон:Indent...Шаблон:Indent«Шаблон:Pipe _ => expression» Шаблон:Ref
| |
Haskell (GHC) | if condition then expression else expression or when condition (do instructions) or unless notcondition (do instructions)
|
result Шаблон:Pipe condition = expressionШаблон:IndentШаблон:Pipe condition = expressionШаблон:IndentШаблон:Pipe otherwise = expression
|
case value of { Шаблон:Indentpattern1 -> expression;Шаблон:Indentpattern2 -> expression;Шаблон:Indent...Шаблон:Indent«_ -> expression» Шаблон:Ref
| |
Bash shell | if condition-command; thenШаблон:Indentexpression
|
if condition-command; thenШаблон:Indentexpression
|
case "$variable" inШаблон:Indent"$condition1" )Шаблон:Indentcommand...Шаблон:Indent"$condition2" )Шаблон:Indentcommand...
|
|
CoffeeScript | if condition then expression «else expression» or if conditionШаблон:Indentexpression or expression if condition or unless conditionШаблон:Indentexpression or expression unless condition
|
if condition then expression else if condition then expression «else expression» or if conditionШаблон:Indentexpression or unless conditionШаблон:Indentexpression
|
switch expressionШаблон:Indentwhen condition then expressionШаблон:Indentelse expression or switch expressionШаблон:Indentwhen conditionШаблон:IndentexpressionШаблон:Indent«elseШаблон:Indentexpression»
|
All conditions are expressions. |
COBOL | IF condition «THEN»Шаблон:Indentexpression Шаблон:Ref
|
EVALUATE expression «ALSO expression...»Шаблон:IndentWHEN case-or-condition «ALSO case-or-condition...»Шаблон:IndentexpressionШаблон:Indent...Шаблон:Indent«WHEN OTHERШаблон:Indentexpression»
|
||
Rust | if condition { Шаблон:Indentexpression
|
if condition { Шаблон:Indentexpression
|
match variable { Шаблон:Indentpattern1 => expression,Шаблон:Indentpattern2 => expression,Шаблон:Indentpattern3 => expression,Шаблон:Indent«_ => expression» Шаблон:RefШаблон:Ref
|
All conditions are expressions |
if | else if | select case | conditional expression |
- Шаблон:Note 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.
- Шаблон:Note This is pattern matching and is similar to select case but not the same. It is usually used to deconstruct algebraic data types.
- Шаблон:Note In languages of the Pascal family, the semicolon is not part of the statement. It is a separator between statements, not a terminator.
- Шаблон:Note
END-IF
may be used instead of the period at the end. - Шаблон:Note In Rust, the comma (Шаблон: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
{}
).
Loop statements
while loop | do while loop | (count-controlled) for loop | foreach | |
---|---|---|---|---|
Ada[1] | while condition loopШаблон:Indentstatements
|
loopШаблон:IndentstatementsШаблон:Indentexit when not condition
|
for index in «reverse» [first .. last Шаблон:Pipe discrete_type] loopШаблон:Indentstatements
|
for item of «reverse» iterator loopШаблон:Indentstatements or (for [all Шаблон:Pipe some] [in Шаблон:Pipe of] [first .. last Шаблон:Pipe discrete_type Шаблон:Pipe iterator] => predicate) Шаблон:Ref
|
ALGOL 68 | «for index» «from first» «by increment» «to last» «while condition» do statements od
|
for key «to upb list» do «typename val=list[key];» statements od
| ||
«while condition»Шаблон:Indentdo statements od
|
«while statements; condition»Шаблон:Indentdo statements od
|
«for index» «from first» «by increment» «to last» do statements od
| ||
APL | :While conditionШаблон:Indentstatements
|
:RepeatШаблон:Indentstatements
|
:For var«s» :In listШаблон:Indentstatements
|
:For var«s» :InEach listШаблон:Indentstatements
|
C (C99) | Шаблон:Code 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
|
Шаблон:N/a |
Objective-C | for (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
| |||
Java | for (type item : set) instructions
| |||
JavaScript | for (var i = first; i <= last; i++) instructions
|
Since EcmaScript 2015:[11]
| ||
PHP | foreach (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 PowerShell | for ($i = first; $i -le last; $i++) instructions
|
foreach (item in set) instructions
| ||
D | foreach (i; first ... last) instructions
|
foreach («type» item; set) instructions
| ||
Go | for condition { instructions }
|
for i := first; i <= last; i++ { instructions }
|
for key, item := range set { instructions }
| |
Swift | while 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 }
|
Perl | while (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 }
|
Raku | while 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 }
|
Ruby | while conditionШаблон:Indentinstructions or until notconditionШаблон:Indentinstructions
|
beginШаблон:Indentinstructions or beginШаблон:Indentinstructions
|
for i in first..lastШаблон:Indentinstructions or for i in first...last+1Шаблон:Indentinstructions or first.Шаблон:Not a typo(last) { Шаблон:PipeiШаблон:Pipe instructions }
|
for item in setШаблон:Indentinstructions or set.each { Шаблон:PipeitemШаблон:Pipe instructions }
|
Bash shell | while condition ;doШаблон:Indentinstructions or until notcondition ;doШаблон:Indentinstructions
|
Шаблон:N/a | for ((i = first; i <= last; ++i)) ; doШаблон:Indentinstructions
|
for item in set ;doШаблон:Indentinstructions
|
Scala | while (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:Шаблон:IndentloopBlock
|
loopBlock doWhile:Шаблон:IndentconditionBlock
|
first to: last do:Шаблон:IndentloopBlock
|
collection do:Шаблон:IndentloopBlock
|
Common Lisp | (loopШаблон:Indentwhile conditionШаблон:IndentdoШаблон:Indentinstructions) or (do () (notcondition)Шаблон:Indentinstructions)
|
(loopШаблон:IndentdoШаблон:IndentinstructionsШаблон:Indentwhile condition)
|
(loopШаблон:Indentfor i from first to last «by 1»Шаблон:IndentdoШаблон:Indentinstructions) or (dotimes (i N)Шаблон:Indentinstructions) or (do ((i first (1+ i))) ((>=i last))
|
(loopШаблон:Indentfor item in listШаблон:IndentdoШаблон:Indentinstructions) or (loopШаблон:Indentfor item across vectorШаблон:IndentdoШаблон:Indentinstructions) or (dolist (item list)Шаблон:Indentinstructions) 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)
|
Pascal | while condition do beginШаблон:Indentinstructions
|
repeatШаблон:Indentinstructions
|
for i := first «step 1» to last do beginШаблон:Indentinstructions Шаблон:Ref
|
for item in set do instructions
|
Visual Basic | Do While conditionШаблон:Indentinstructions or Do Until notconditionШаблон:Indentinstructions or While conditionШаблон:Indentinstructions (Visual Basic .NET uses Шаблон:Code instead)
|
DoШаблон:Indentinstructions or DoШаблон:Indentinstructions
|
Шаблон:Code must be declared beforehand.
|
For Each item In setШаблон:Indentinstructions
|
Visual Basic .NET | For i« As type» = first To last« Step 1»Шаблон:Indentinstructions Шаблон:Ref
|
For Each item« As type» In setШаблон:Indentinstructions
| ||
Xojo | While conditionШаблон:Indentinstructions
|
Do Until notconditionШаблон:Indentinstructions or DoШаблон:Indentinstructions
| ||
Python | while condition :
|
Шаблон:N/a | Python 3.x:for i in range(first, last+1): Python 2.x: for i in xrange(first, last+1):
|
for item in set:
|
S-Lang | while (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»
|
Fortran | DO WHILE (condition)Шаблон:Indentinstructions
|
DOШаблон:IndentinstructionsШаблон:IndentIF (condition) EXIT
|
DO I = first,lastШаблон:Indentinstructions
|
Шаблон:N/a |
Forth | BEGIN «instructions» condition WHILE instructions REPEAT
|
BEGIN instructions condition UNTIL
|
limit start DO instructions LOOP
|
Шаблон:N/a |
OCaml | while condition do instructions done
|
Шаблон:N/a | for i = first to last do instructions done
|
Array.iter (fun item -> instructions) array or List.iter (fun item -> instructions) list
|
F# | while condition do
|
Шаблон:N/a | for i = first to last do
|
foritem in set do or Seq.iter (fun item -> instructions) set
|
Standard ML | while condition do ( instructions )
|
colspan=2 Шаблон:N/a | Array.app (fn item => instructions) array or app (fn item => instructions) list
| |
Haskell (GHC) | colspan=2 Шаблон:N/a | Control.Monad.forM_ [first..last] (\i -> do instructions)
|
Control.Monad.forM_list (\item -> do instructions)
| |
Eiffel | fromШаблон:Indentsetup
| |||
CoffeeScript | while conditionШаблон:Indentexpression or expression while condition or while condition then expression or until conditionШаблон:Indentexpression or expression until condition or until expression then condition
|
Шаблон:N/a | for i in [first..last]Шаблон:Indentexpression or for i in [first..last] then expression or expression for i in [first..last]
|
for item in setШаблон:Indentexpression or for item in set then expression or expression for item in set
|
COBOL | PERFORM procedure-1 «THROUGH procedure-2» ««WITH» TEST BEFORE» UNTIL condition Шаблон:Refor PERFORM ««WITH» TEST BEFORE» UNTIL conditionШаблон:Indentexpression
|
PERFORM procedure-1 «THROUGH procedure-2» «WITH» TEST AFTER UNTIL condition Шаблон:Refor PERFORM «WITH» TEST AFTER UNTIL conditionШаблон:Indentexpression
|
PERFORM procedure-1 «THROUGH procedure-2» VARYING i FROM first BY increment UNTIL i > last Шаблон:Refor PERFORM VARYING i FROM first BY increment UNTIL i > lastШаблон:Indentexpression Шаблон:Ref
|
Шаблон:N/a |
Rust | while condition { Шаблон:Indentexpression
|
loop { Шаблон:IndentexpressionШаблон:Indentif condition { Шаблон:Indentbreak;Шаблон:Indent}
|
for i in first..last+1 { Шаблон:Indentexpression or for i in first..=last { Шаблон:Indentexpression
|
for item in set { Шаблон:Indentexpression Шаблон:Refor set.into_iter().for_each(Шаблон:PipeitemШаблон:Pipe expression); Шаблон:Ref
|
- Шаблон:Note "
step
n" is used to change the loop interval. If "step
" is omitted, then the loop interval is 1. - Шаблон:Note This implements the universal quantifier ("for all" or "<math>\forall</math>") as well as the existential quantifier ("there exists" or "<math>\exists</math>").
- Шаблон:Note
THRU
may be used instead ofTHROUGH
. - Шаблон:Note
«IS» GREATER «THAN»
may be used instead of>
. - Шаблон:Note Type of set expression must implement trait
std::iter::IntoIterator
.
Exceptions
throw | handler | assertion | |
---|---|---|---|
Ada[1] | raise exception_name «with string_expression»
|
beginШаблон:Indentstatements Шаблон:Ref
|
pragma Assert («Check =>» boolean_expression ««Message =>» string_expression»)
|
APL | «string_expression» ⎕SIGNAL number_expression
|
:Trap number«s»_expressionШаблон:Indentstatements
|
«string_expression» ⎕SIGNAL 98/⍨~condition
|
C (C99) | longjmp(state, exception);
|
switch (setjmp(state)) { case 0: instructions break; case exception: instructions ... }
|
assert(condition);
|
C++ | throw exception;
|
try { instructions } catch «(exception)» { instructions } ...
| |
C# | try { instructions } catch «(exception« name»)» { instructions } ... «finally { instructions }»
|
System.Diagnostics.Debug.Assert(condition); or System.Diagnostics.Trace.Assert(condition);
| |
Java | try { instructions } catch (exception) { instructions } ... «finally { instructions }»
|
assert condition «: description»;
| |
JavaScript | try { instructions } catch (exception) { instructions} «finally { instructions }»
|
Шаблон:Dunno | |
D | try { instructions } catch (exception) { instructions } ... «finally { instructions }»
|
assert(condition);
| |
PHP | try { instructions } catch (exception) { instructions } ... «finally { instructions }»
|
assert(condition);
| |
S-Lang | try { instructions } catch «exception» { instructions } ... «finally { instructions }»
|
Шаблон:Dunno | |
Windows PowerShell | trap «[exception]» { instructions } ... instructions or try { instructions } catch «[exception]» { instructions } ... «finally { instructions }»
|
[Debug]::Assert(condition)
| |
Objective-C | @throw exception;
|
@try { instructions } @catch (exception) { instructions } ... «@finally { instructions }»
|
NSAssert(condition, description);
|
Swift | throw exception (2.x)
|
do { try expression ... instructions } catch exception { instructions } ... (2.x)
|
assert(condition«, description»)
|
Perl | die exception;
|
eval { instructions }; if ($@) { instructions }
|
Шаблон:Dunno |
Raku | try { instructions CATCH { when exception { instructions } ...}}
|
Шаблон:Dunno | |
Ruby | raise exception
|
beginШаблон:Indentinstructions
|
|
Smalltalk | exception raise
|
instructionBlock on: exception do: handlerBlock
|
assert: conditionBlock
|
Common Lisp | (error "exception") or (errorШаблон:IndenttypeШаблон:Indentarguments) or (error (make-conditionШаблон:IndenttypeШаблон:Indentarguments))
|
(handler-caseШаблон:Indent(progn instructions)Шаблон:Indent(exception instructions)Шаблон:Indent...) or (handler-bindШаблон:Indent(conditionШаблон:Indent(lambdaШаблон:IndentinstructionsШаблон:Indent«invoke-restart restart args»)) Шаблон:Ref
|
(assert condition) or (assert conditionШаблон:Indent«(place)Шаблон:Indent«error»») or (check-type var type)
|
Scheme (R6RS) | (raise exception)
|
(guard (con (condition instructions) ...) instructions)
|
Шаблон:Dunno |
ISLISP | (error "error-string" objects) or (signal-condition condition continuable)
|
(with-handlerШаблон:Indenthandler form*
|
Шаблон:Dunno |
Pascal | raise Exception.Create()
|
try Except on E: exception do begin instructions end; end;
|
Шаблон:Dunno |
Visual Basic | Err.Raise ERRORNUMBER
|
With New Try: On Error Resume NextШаблон:IndentOneInstruction '*** 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
|
Debug.Assert condition
|
Visual Basic .NET | Throw exception or Error errorcode
|
TryШаблон:Indentinstructions
|
System.Diagnostics. Debug.Assert(condition) or System.Diagnostics.Trace.Assert(condition)
|
Xojo | Raise exception
|
TryШаблон:Indentinstructions
|
Шаблон:N/a |
Python | raise exception
|
try:
|
assert condition
|
Fortran | colspan=3 Шаблон:N/a | ||
Forth | code THROW
|
xt CATCH ( code or 0 )
|
Шаблон:N/a |
OCaml | raise exception
|
try expression with pattern -> expression ...
|
assert condition
|
F# | try expression with pattern -> expression ... or try expression finally expression
| ||
Standard ML | raise exception «arg»
|
expression handle pattern => expression ...
|
|
Haskell (GHC) | throw exception or throwError expression
|
catch tryExpression catchExpression or catchError tryExpression catchExpression
|
assert condition expression
|
COBOL | RAISE «EXCEPTION» exception
|
USE «AFTER» EXCEPTION OBJECT class-name. or USE «AFTER» EO class-name. or USE «AFTER» EXCEPTION CONDITION exception-name «FILE file-name». or USE «AFTER» EC exception-name «FILE file-name».
|
Шаблон:N/a |
Rust | colspan=2 Шаблон:No[13] | assert!(condition)
|
- Шаблон:Note Common Lisp allows Шаблон:Code, Шаблон:Code and Шаблон:Code to define restarts for use with Шаблон:Code. Unhandled conditions may cause the implementation to show a restarts menu to the user before unwinding the stack.
- Шаблон:Note 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).
Other control flow statements
exit block (break) | continue | label | branch (goto) | return value from generator | |
---|---|---|---|---|---|
Ada[1] | exit «loop_name» «when condition»
|
Шаблон:N/a | label:
|
goto label
|
Шаблон:N/a |
ALGOL 68 | value exit; ...
|
do statements; skip exit; label: statements od
|
Шаблон:Code ... | go to label; ...
|
yield(value)
|
APL | :Leave
|
:Continue
|
label:
|
→label or :GoTo label
|
Шаблон:N/a |
C (C99) | break;
|
continue;
|
label:
|
goto label;
|
rowspan=4 Шаблон:N/a |
Objective-C | |||||
C++ (STL) | |||||
D | |||||
C# | yield return value;
| ||||
Java | break «label»;
|
continue «label»;
|
rowspan=2 Шаблон:N/a | ||
JavaScript | yield value«;»
| ||||
PHP | break «levels»;
|
continue «levels»;
|
goto label;
|
yield «key =>» value;
| |
Perl | last «label»;
|
next «label»;
|
|||
Raku | |||||
Go | break «label»
|
continue «label»
|
goto label
|
||
Swift | break «label»
|
continue «label»
|
Шаблон:N/a | ||
Bash shell | break «levels»
|
continue «levels»
|
Шаблон:N/a | Шаблон:N/a | Шаблон:N/a |
Common Lisp | (return) or (return-from block) or (loop-finish)
|
(tagbody tagШаблон:Indent...Шаблон:Indenttag
|
(go tag)
|
||
Scheme | |||||
ISLISP | (return-from block)
|
(tagbody tagШаблон:Indent...Шаблон:Indenttag
|
(go tag)
|
||
Pascal (ISO) | colspan=2 Шаблон:N/a | label: Шаблон:Ref
|
goto label;
|
rowspan=4 Шаблон:N/a | |
Pascal (FPC) | break;
|
continue;
| |||
Visual Basic | Exit block Alternatively, for methods,Шаблон:Code |
Шаблон:N/a | label:
|
GoTo label
| |
Xojo | Continue block
| ||||
Visual Basic .NET | Yield value
| ||||
Python | break
|
continue
|
colspan=2 Шаблон:N/a | yield value
| |
RPG IV | LEAVE;
|
ITER;
|
|||
S-Lang | break;
|
continue;
|
|||
Fortran | EXIT
|
CYCLE
|
Шаблон:CodeШаблон:Ref | GOTO label
|
Шаблон:N/a |
Ruby | break
|
next
|
|||
Windows PowerShell | break «label»
|
continue
|
|||
OCaml | rowspan=4 colspan=4 Шаблон:N/a | ||||
F# | |||||
Standard ML | |||||
Haskell (GHC) | |||||
COBOL | EXIT PERFORM or EXIT PARAGRAPH or EXIT SECTION or EXIT.
|
EXIT PERFORM CYCLE
|
label «SECTION».
|
GO TO label
|
Шаблон:N/a |
- Шаблон:Note Pascal has declaration blocks. See functions.
- Шаблон:Note label must be a number between 1 and 99999.
Functions
See reflection for calling and declaring functions by strings.
calling a function | basic/void function | value-returning function | required main function | |
---|---|---|---|---|
Ada[1] | foo «(parameters)»
|
procedure foo «(parameters)» is begin statements end foo
|
function foo «(parameters)» return type is begin statements end foo
|
Шаблон:N/a |
ALGOL 68 | foo «(parameters)»;
|
proc foo = «(parameters)» void: ( instructions );
|
proc foo = «(parameters)» rettype: ( instructions ...; retvalue );
|
Шаблон:N/a |
APL | «parameters» foo parameters
|
foo←{ statements }
|
foo←{ statements }
|
Шаблон:N/a |
C (C99) | foo(«parameters»)
|
void foo(«parameters») { instructions }
|
type foo(«parameters») { instructions ... return value; }
|
«global declarations»
|
Objective-C | ||||
C++ (STL) | ||||
Java | public static void main(String[] args) { instructions } or public static void main(String... args) { instructions }
| |||
D | int main(«char[][] args») { instructions} or int main(«string[] args») { instructions} or void main(«char[][] args») { instructions} or void main(«string[] args») { instructions}
| |||
C# | Same as above; alternatively, if only one statement:
|
Same as above; alternatively, if simple enough to be an expression:
|
static void Main(«string[] args») method_body May instead return Шаблон:Code. (starting with C# 7.1:) May return Шаблон:Code or Шаблон:Code, and if so, may be Шаблон:Code. | |
JavaScript | function foo(«parameters») { instructions } or var foo = function («parameters») { instructions } or var foo = new Function ("«parameter»", ..., "«last parameter»" "instructions");
|
function foo(«parameters») { instructions ... return value; }
|
Шаблон:N/a | |
Go | func foo(«parameters») { instructions }
|
func foo(«parameters») type { instructions ... return value }
|
func main() { instructions }
| |
Swift | func foo(«parameters») { instructions }
|
func foo(«parameters») -> type { instructions ... return value }
|
Шаблон:N/a | |
Common Lisp | (foo «parameters»)
|
(defun foo («parameters»)Шаблон:Indentinstructions) or (setf (symbol-function 'symbol)Шаблон:Indentfunction)
|
(defun foo («parameters»)Шаблон:Indent...Шаблон:Indentvalue)
|
rowspan=3 Шаблон:N/a |
Scheme | (define (foo parameters) instructions) or (define foo (lambda (parameters) instructions))
|
(define (foo parameters) instructions... return_value) or (define foo (lambda (parameters) instructions... return_value))
| ||
ISLISP | (defun foo («parameters»)Шаблон:Indentinstructions)
|
(defun foo («parameters»)Шаблон:Indent...Шаблон:Indentvalue)
| ||
Pascal | foo«(parameters)»
|
procedure foo«(parameters)»; «forward;»Шаблон:Ref
|
function foo«(parameters)»: type; «forward;»Шаблон:Ref
|
program name;
|
Visual Basic | Foo(«parameters»)
|
Sub Foo«(parameters)»Шаблон:Indentinstructions
|
Function Foo«(parameters)»« As type»Шаблон:IndentinstructionsШаблон:IndentFoo = value
|
Sub Main()Шаблон:Indentinstructions
|
Visual Basic .NET | Same as above; alternatively:
|
Sub Main(««ByVal »args() As String»)Шаблон:Indentinstructions orFunction Main(««ByVal »args() As String») As IntegerШаблон:Indentinstructions
| ||
Xojo | ||||
Python | foo(«parameters»)
|
def foo(«parameters»):
|
def foo(«parameters»):
|
Шаблон:N/a |
S-Lang | foo(«parameters» «;qualifiers»)
|
define foo («parameters») { instructions }
|
define foo («parameters») { instructions ... return value; }
|
public define slsh_main () { instructions }
|
Fortran | foo («arguments») Шаблон:Ref
|
SUBROUTINE sub_foo («arguments»)Шаблон:Indentinstructions Шаблон:Ref
|
type FUNCTION foo («arguments»)Шаблон:IndentinstructionsШаблон:Indent...Шаблон:Indentfoo = value Шаблон:Ref
|
PROGRAM mainШаблон:Indentinstructions
|
Forth | «parameters» FOO
|
: FOO « stack effect comment: ( before -- ) »Шаблон:Indentinstructions
|
: FOO « stack effect comment: ( before -- after ) »Шаблон:Indentinstructions
|
Шаблон:N/a |
PHP | foo(«parameters»)
|
function foo(«parameters») { instructions }
|
function foo(«parameters») { instructions ... return value; }
|
rowspan=4 Шаблон:N/a |
Perl | foo(«parameters») or &foo«(parameters)»
|
sub foo { «my (parameters) = @_;» instructions }
|
sub foo { «my (parameters) = @_;» instructions... «return» value; }
| |
Raku | foo(«parameters») or &foo«(parameters)»
|
«multi »sub foo(parameters) { instructions }
|
«our «type» »«multi »sub foo(parameters) { instructions ... «return» value; }
| |
Ruby | foo«(parameters)»
|
def foo«(parameters)»Шаблон:Indentinstructions
|
def foo«(parameters)»Шаблон:IndentinstructionsШаблон:Indent«return» value
| |
Rust | foo(«parameters»)
|
fn foo(«parameters») { instructions }
|
fn foo(«parameters») -> type { instructions }
|
fn main() { instructions }
|
Scala | foo«(parameters)»
|
def foo«(parameters)»«: Unit =» { instructions }
|
def foo«(parameters)»«: type» = { instructions ... «return» value }
|
def main(args: Array[String]) { instructions }
|
Windows PowerShell | foo «parameters»
|
function foo { instructions }; or function foo { «param(parameters)» instructions }
|
function foo «(parameters)» { instructions ... return value }; or function foo { «param(parameters)» instructions ... return value }
|
rowspan=4 Шаблон:N/a |
Bash shell | foo «parameters»
|
function foo {Шаблон:Indentinstructions or foo () {Шаблон:Indentinstructions
|
function foo {Шаблон:IndentinstructionsШаблон:Indentreturn «exit_code» or foo () { Шаблон:IndentinstructionsШаблон:Indentreturn «exit_code»
| |
| ||||
OCaml | foo parameters
|
let «rec» foo parameters = instructions
|
let «rec» foo parameters = instructions... return_value
| |
F# | [<EntryPoint>] let main args = instructions
| |||
Standard ML | fun foo parameters = ( instructions )
|
fun foo parameters = ( instructions... return_value )
|
||
Haskell | foo parameters = do
|
foo parameters = return_value or foo parameters = do
|
«main :: IO ()»
| |
Eiffel | foo («parameters»)
|
foo («parameters»)Шаблон:IndentrequireШаблон:IndentpreconditionsШаблон:IndentdoШаблон:IndentinstructionsШаблон:IndentensureШаблон:IndentpostconditionsШаблон:Indentend
|
foo («parameters»): typeШаблон:IndentrequireШаблон:IndentpreconditionsШаблон:IndentdoШаблон:IndentinstructionsШаблон:IndentResult := valueШаблон:IndentensureШаблон:IndentpostconditionsШаблон:Indentend
|
Шаблон:Ref |
CoffeeScript | foo()
|
foo = ->
|
foo = -> value
|
rowspan=2 Шаблон:N/a |
foo parameters
|
foo = () ->
|
foo = ( parameters ) -> value
| ||
COBOL | CALL "foo" «USING parameters»Шаблон:Indent«exception-handling» Шаблон:Ref
|
«IDENTIFICATION DIVISION.»
|
«IDENTIFICATION DIVISION.»
|
rowspan=2 Шаблон:N/a |
«FUNCTION» foo«(«parameters»)»
|
Шаблон:N/a |
- Шаблон:Note Pascal requires "Шаблон:Code" for forward declarations.
- Шаблон:Note Eiffel allows the specification of an application's root class and feature.
- Шаблон:Note In Fortran, function/subroutine parameters are called arguments (since Шаблон:Code is a language keyword); the Шаблон:Code keyword is required for subroutines.
- Шаблон:Note Instead of using Шаблон:Code, a string variable may be used instead containing the same value.
Type conversionsШаблон:Anchor
Where string is a signed decimal number:
string to integer | string to long integer | string to floating point | integer to string | floating point to string | |
---|---|---|---|---|---|
Ada[1] | Integer'Value (string_expression)
|
Long_Integer'Value (string_expression)
|
Float'Value (string_expression)
|
Integer'Image (integer_expression)
|
Float'Image (float_expression)
|
ALGOL 68 with general, and then specific formats | With prior declarations and association of: string buf := "12345678.9012e34 "; file proxy; associate(proxy, buf);
| ||||
Шаблон:Code | Шаблон:Code | Шаблон:Code | Шаблон:Code | Шаблон:Code | |
Шаблон:Code or Шаблон:Code |
Шаблон:Code or Шаблон:Code |
Шаблон:Code or Шаблон:Code |
Шаблон:Code or Шаблон:Code |
Шаблон:Code or Шаблон:Code | |
APL | ⍎string_expression
|
⍎string_expression
|
⍎string_expression
|
⍕integer_expression
|
⍕float_expression
|
C (C99) | integer = atoi(string);
|
long = atol(string);
|
float = atof(string);
|
sprintf(string, "%i", integer);
|
sprintf(string, "%f", float);
|
Objective-C | integer = [string intValue];
|
long = [string longLongValue];
|
float = [string doubleValue];
|
string = [NSString stringWithFormat
|
string = [NSString stringWithFormat
|
C++ (STL) | «std::»istringstream(string) >> number;
|
«std::»ostringstream o; o << number; string = o.str();
| |||
C++11 | integer = «std::»stoi(string);
|
long = «std::»stol(string);
|
float = «std::»stof(string); double = «std::»stod(string);
|
string = «std::»to_string(number);
| |
C# | integer = int.Parse
|
long = long.Parse
|
float = float.Parse double = double.Parse
|
string = number
| |
D | integer = std.conv.to!int
|
long = std.conv.to!long
|
float = std.conv.to!float double = std.conv.to!double
|
string = std.conv.to!string
| |
Java | integer = Integer.parseInt
|
long = Long.parseLong
|
float = Float.parseFloat double = Double.parseDouble
|
string = Integer.toString string = String.valueOf
|
string = Float.toString string = Double.toString
|
JavaScriptШаблон:Ref | integer = parseInt(string);
|
float = parseFloat(string); float = new Number (string); float = Number (string); float = +string;
|
string = number.toString (); string = String (number); string = number+""; string = `${number}`
| ||
Go | integer, error = strconv.Atoi(string)
|
long, error = strconv.ParseInt
|
float, error = strconv.ParseFloat
|
string = strconv.Itoa(integer) string = strconv.FormatInt string = fmt.Sprint(integer)
|
string = strconv.FormatFloat string = fmt.Sprint
|
RustШаблон:Ref | string.parse::<i32>() i32::from_str(string)
|
string.parse::<i64>() i64::from_str(string)
|
string.parse::<f64>() f64::from_str(string)
|
integer.to_string()
|
float.to_string()
|
Common Lisp | (setf integer (parse-integer string))
|
(setf float (read-from-string string))
|
(setf string (princ-to-string number))
| ||
Scheme | (define number (string->number string))
|
(define string (number->string number))
| |||
ISLISP | (setf integer (convert string <integer>))
|
(setf float (convert string <float>))
|
(setf string (convert number <string>))
| ||
Pascal | integer := StrToInt(string);
|
float := StrToFloat(string);
|
string := IntToStr(integer);
|
string := FloatToStr(float);
| |
Visual Basic | integer = CInt(string)
|
long = CLng(string)
|
float = CSng(string)
|
string = CStr(number)
|
|
Visual Basic .NET (can use both VB syntax above and .NET methods shown right) |
integer = Integer.Parse
|
long = Long.Parse
|
float = Single.Parse double = Double.Parse
|
string = number
| |
Xojo | integer = Val(string)
|
long = Val(string)
|
double = Val(string) double = CDbl(string)
|
string = CStr(number) or string = Str(number)
| |
Python | integer = int(string)
|
long = long(string)
|
float = float(string)
|
string = str(number)
| |
S-Lang | integer = atoi(string);
|
long = atol(string);
|
float = atof(string);
|
string = string(number);
| |
Fortran | READ(string,format) number
|
WRITE(string,format) number
| |||
PHP | integer = intval(string); or integer = (int)string;
|
float = floatval(string); float = (float)string;
|
string = "$number"; or string = strval(number); or string = (string)number;
| ||
PerlШаблон:Ref | number = 0 + string;
|
string = "number";
| |||
Raku | number = +string;
|
string = ~number;
| |||
Ruby | integer = string.to_i or integer = Integer(string)
|
float = string.to_f float = Float(string)
|
string = number.to_s
| ||
Scala | integer = string.toInt
|
long = string.toLong
|
float = string.toFloat double = string.toDouble
|
string = number.toString
| |
Smalltalk | integer := Integer readFrom: string
|
float := Float readFrom: string
|
string := number asString
| ||
Windows PowerShell | integer = [int]string
|
long = [long]string
|
float = [float]string
|
string = [string]number; or string = "number"; or string = (number).ToString()
| |
OCaml | let integer = int_
|
let float = float_
|
let string = string_
|
let string = string_
| |
F# | let integer = int string
|
let integer = int64 string
|
let float = float string
|
let string = string number
| |
Standard ML | val integer = Int
|
val float = Real
|
val string = Int
|
val string = Real
| |
Haskell (GHC) | number = read string
|
string = show number
| |||
COBOL | MOVE «FUNCTION» NUMVAL(string)Шаблон:Ref TO number
|
MOVE number TO numeric-edited
|
- Шаблон:Note JavaScript only uses floating point numbers so there are some technicalities.[7]
- Шаблон:Note Perl doesn't have separate types. Strings and numbers are interchangeable.
- Шаблон:Note Шаблон:Code or Шаблон:Code may be used instead of Шаблон:Code.
- Шаблон:Note Шаблон:Code is available to convert any type that has an implementation of the Шаблон:Code trait. Both Шаблон:Code and Шаблон:Code return a [[result type|Шаблон:Code]] that contains the specified type if there is no error. The turbofish (Шаблон:Code) on Шаблон:Code can be omitted if the type can be inferred from context.
Standard stream I/O
read from | write to | ||
---|---|---|---|
stdin | stdout | stderr | |
Ada[1] | Get (x)
|
Put (x)
|
Put (Standard_Error, x)
|
ALGOL 68 | readf(($format$, x)); or getf(stand in, ($format$, x));
|
printf(($format$, x)); or putf(stand out, ($format$, x));
|
putf(stand error, ($format$, x)); Шаблон:Ref
|
APL | x←⎕
|
⎕←x
|
⍞←x
|
C (C99) | scanf(format, &x); or fscanf(stdin, format, &x); Шаблон:Ref
|
printf(format, x); or fprintf(stdout, format, x); Шаблон:Ref
|
fprintf(stderr, format, x); Шаблон:Ref
|
Objective-C | data = [[NSFileHandle fileHandleWithStandardInput] readDataToEndOfFile];
|
[[NSFileHandle fileHandleWithStandardOutput] writeData:data];
|
[[NSFileHandle fileHandleWithStandardError] writeData:data];
|
C++ | «std::»cin >> x; or «std::»getline(«std::»cin, str);
|
«std::»cout << x;
|
«std::»cerr << x; or «std::»clog << x;
|
C# | x = Console.Read(); or x = Console.ReadLine();
|
Console.Write(«format, »x); or Console.WriteLine(«format, »x);
|
Console.Error or Console.Error
|
D | x = std.stdio.readln()
|
std.stdio.write(x) or std.stdio.writeln(x) or std.stdio.writef(format, x) or std.stdio.writefln(format, x)
|
stderr.write(x) or stderr.writeln(x) or std.stdio or std.stdio
|
Java | Шаблон:Code or Шаблон:Code or Шаблон:Code |
System.out.print(x); or System.out.printf(format, x); or System.out.println(x);
|
System.err.print(x); or System.err.printf(format, x); or System.err.println(x);
|
Go | fmt.Scan(&x) or fmt.Scanf(format, &x) or Шаблон:Code |
fmt.Println(x) or fmt.Printf(format, x)
|
fmt.Fprintln(osШаблон:Not a typoStderr, x) or fmt.Fprintf(osШаблон:Not a typoStderr, format, x)
|
Swift | x = readLine() (2.x)
|
print(x) (2.x)println(x) (1.x)
|
|
JavaScript Web Browser implementation |
document.write(x)
|
||
JavaScript Active Server Pages |
Response.Write(x)
|
||
JavaScript Windows Script Host |
x = WScript.StdIn.Read(chars) or x = WScript.StdIn.ReadLine()
|
WScript.Echo(x) or WScript.StdOut.Write(x) or WScript.StdOut.WriteLine(x)
|
WScript.StdErr.Write(x) or WScript.StdErr.WriteLine(x)
|
Common Lisp | Шаблон:Code | (princ x) or (format t format x)
|
Шаблон:Code or Шаблон:Codett format x)
|
Scheme (R6RS) | Шаблон:Code | (display x) or Шаблон:Codett format x)
|
Шаблон:Code or Шаблон:Codett format x)
|
ISLISP | Шаблон:Code | Шаблон:Codett format x)
|
Шаблон:Codett format x)
|
Pascal | read(x); or readln(x);
|
write(x); or writeln(x);
|
write(stderr, x); or writeln(stderr, x);
|
Visual Basic | Input« prompt,» x
|
Print x or ? x
|
Шаблон:N/a |
Visual Basic .NET | x = Console.Read() or x = Console.ReadLine()
|
Console.Write(«format,»x) or Console.WriteLine(«format, »x)
|
Console.Error or Console.Error
|
Xojo | x = StandardInputStream.Read() or x = StandardInputStreame.ReadLine()
|
StandardOutputStream.Write(x) or StandardOutputStream.WriteLine(x)
|
StdErr.Write(x) or StdErr.WriteLine(x)
|
Python 2.x | x = raw_input(«prompt»)
|
print x or sys.stdout.write(x)
|
Шаблон:Codett x or sys.stderr.write(x)
|
Python 3.x | x = input(«prompt»)
|
print(x«, end=""»)
|
print(x«, end=""», file=sys.stderr)
|
S-Lang | fgets (&x, stdin)
|
fputs (x, stdout)
|
fputs (x, stderr)
|
Fortran | READ(*,format) variable names or READ(INPUT_UNIT,format) variable names Шаблон:Ref
|
WRITE(*,format) expressions or WRITE(OUTPUT_UNIT,format) expressions Шаблон:Ref
|
WRITE(ERROR_UNIT,format) expressions Шаблон:Ref
|
Forth | buffer length ACCEPT ( # chars read )
|
buffer length TYPE
|
Шаблон:N/a |
PHP | $x = fgets(STDIN); or $x = fscanf(STDIN, format);
|
print x; or echo x; or printf(format, x);
|
fprintf(STDERR, format, x);
|
Perl | $x = <>; or $x = <STDIN>;
|
print x; or printf format, x;
|
print STDERR x; or printf STDERR format, x;
|
Raku | Шаблон:Code | x.print or x.say
|
x.note or Шаблон:Code or Шаблон:Code |
Ruby | x = gets
|
puts x or printf(format, x)
|
Шаблон:Code or $stderr.printf(format, x)
|
Windows PowerShell | $x = Read-Host«« -Prompt» text»; or Шаблон:Code or Шаблон:Code |
x; or Write-Output x; or echo x
|
Write-Error x
|
OCaml | let x = read_int () or let str = read_line () or Scanf.scanf format (fun x ... -> ...)
|
print_int x or print_endline str or Printf.printf format x ...
|
prerr_int x or prerr_endline str or Printf.eprintf format x ...
|
F# | Шаблон:Code | printf format x ... or printfn format x ...
|
eprintf format x ... or eprintfn format x ...
|
Standard ML | Шаблон:Code | print str
|
Шаблон:Codett str)
|
Haskell (GHC) | x <- readLn or str <- getLine
|
print x or putStrLn str
|
hPrint stderr x or hPutStrLn stderr str
|
COBOL | ACCEPT x
|
DISPLAY x
|
- Шаблон:Note ALGOL 68 additionally as the "unformatted" transput routines:
read
,write
,get
, andput
. - Шаблон:Note
gets(x)
andfgets(x, length, stdin)
read unformatted text from stdin. Use of gets is not recommended. - Шаблон:Note
puts(x)
andfputs(x, stdout)
write unformatted text to stdout. - Шаблон:Note
fputs(x, stderr)
writes unformatted text to stderr - Шаблон:Note Шаблон:Mono are defined in the Шаблон:Mono module.[15]
Reading command-line arguments
Argument values | Argument counts | Program name / Script name | |
---|---|---|---|
Ada[1] | Argument (n)
|
Argument_Count
|
Command_Name
|
C (C99) | argv[n]
|
argc
|
first argument |
Objective-C | |||
C++ | |||
C# | args[n]
|
args.Length
|
Assembly.GetEntryAssembly()
|
Java | args.length
|
||
D | first argument | ||
JavaScript Windows Script Host implementation |
WScript.Arguments(n)
|
WScript.Arguments.length
|
WScript.ScriptName or WScript.ScriptFullName
|
Go | os.Args[n]
|
len(os.Args)
|
first argument |
RustШаблон:Ref | std::env::args().nth(n) std::env::args_os().nth(n)
|
std::env::args().count() std::env::args_os().count()
|
std::env::args().next() std::env::args_os().next()
|
Swift | Process.arguments[n] orProcess.unsafeArgv[n]
|
Process.arguments.count orProcess.argc
|
first argument |
Common Lisp | Шаблон:Dunno | Шаблон:Dunno | Шаблон:Dunno |
Scheme (R6RS) | Шаблон:Code | Шаблон:Code | first argument |
ISLISP | Шаблон:N/a | Шаблон:N/a | Шаблон:N/a |
Pascal | ParamStr(n)
|
ParamCount
|
first argument |
Visual Basic | Command Шаблон:Ref
|
Шаблон:N/a | App.Path
|
Visual Basic .NET | CmdArgs(n)
|
CmdArgs.Length
|
[Assembly].GetEntryAssembly().Location
|
Xojo | System.CommandLine
|
(string parsing) | Application.ExecutableFile.Name
|
Python | sys.argv[n]
|
len(sys.argv)
|
first argument |
S-Lang | __argv[n]
|
__argc
|
first argument |
Fortran | DO i = 1,argcШаблон:IndentCALL GET_COMMAND_ARGUMENT (i,argv(i))
|
argc = COMMAND_ARGUMENT_COUNT ()
|
CALL GET_COMMAND_ARGUMENT (0,progname)
|
PHP | $argv[n]
|
$argc
|
first argument |
Bash shell | $n ($1, $2, $3, ...) $@ (all arguments)
|
$#
|
$0
|
Perl | $ARGV[n]
|
scalar(@ARGV)
|
$0
|
Raku | @*ARGS[n]
|
@*ARGS.elems
|
$PROGRAM_NAME
|
Ruby | ARGV[n]
|
ARGV.size
|
$0
|
Windows PowerShell | $args[n]
|
$args.Length
|
$MyInvocation.MyCommand
|
OCaml | Sys.argv.(n)
|
Array.length Sys.argv
|
first argument |
F# | args.[n]
|
args.Length
|
Assembly.GetEntryAssembly()
|
Standard ML | Шаблон:Code | Шаблон:Code | Шаблон:Code |
Haskell (GHC) | Шаблон:Code} | Шаблон:Code} | System.getProgName
|
COBOL | Шаблон:Ref | Шаблон:N/a |
- Шаблон:Note In Rust, Шаблон:Code and Шаблон:Code return iterators, Шаблон:Code and Шаблон:Code respectively. Шаблон:Code converts each argument to a Шаблон:Code and it panics if it reaches an argument that cannot be converted to UTF-8. Шаблон:Code returns a non-lossy representation of the raw strings from the operating system (Шаблон:Code), which can be invalid UTF-8.
- Шаблон:Note In Visual Basic, command-line arguments are not separated. Separating them requires a split function
Split(string)
. - Шаблон:Note 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 statements.
Execution of commands
Shell command | Execute program | Replace current program with new executed program | |
---|---|---|---|
Ada[1] | Not part of the language standard. Commonly done by compiler provided packages or by interfacing to C or POSIX.[16] | ||
C | system("command");
|
execl(path, args); or execv(path, arglist);
| |
C++ | |||
Objective-C | Шаблон:Code | ||
C# | System.Diagnostics
|
||
F# | |||
Go | exec.Run(path, argv, envv, dir, exec.DevNull, exec.DevNull, exec.DevNull)
|
os.Exec(path, argv, envv)
| |
Visual Basic | Interaction.Shell(command «, WindowStyle» «, isWaitOnReturn»)
|
||
Visual Basic .NET | Microsoft.VisualBasic
|
System.Diagnostics
|
|
Xojo | Shell.Execute(command «, Parameters»)
|
FolderItem.Launch(parameters, activate)
|
Шаблон:N/a |
D | std.process.system("command");
|
std.process.execv(path, arglist);
| |
Java | Runtime.exec(command); or Шаблон:Code |
||
JavaScript Windows Script Host implementation |
Шаблон:Codettcommand «, WindowStyle» «, isWaitOnReturn»);
|
WshShell.Exec(command)
|
|
Common Lisp | (uiop:run-program command)
|
||
Scheme | (system command)
|
||
ISLISP | Шаблон:N/a | Шаблон:N/a | Шаблон:N/a |
Pascal | system(command);
|
||
OCaml | Sys.command command, Unix.open_process_full command env (stdout, stdin, stderr),...
|
Unix.create_process prog args new_stdin new_stdout new_stderr, ...
|
Unix.execv prog args or Unix.execve prog args env
|
Standard ML | OS.Process.system command
|
Unix.execute (path, args)
|
Posix.Process.exec (path, args)
|
Haskell (GHC) | System.system command
|
System.Process
|
Posix.Process
|
Perl | system(command) or $output = `command` or $output = qx(command)
|
exec(path, args)
| |
Ruby | system(command) or output = `command`
|
exec(path, args)
| |
PHP | system(command) or $output = `command` or exec(command) or passthru(command)
|
||
Python | os.system(command) or subprocess.Popen(command)
|
subprocess.call(["program", "arg1", "arg2", ...])
|
os.execv(path, args)
|
S-Lang | system(command)
|
||
Fortran | CALL EXECUTE_COMMAND_LINE (COMMAND «, WAIT» «, EXITSTAT» «, CMDSTAT» «, CMDMSG») Шаблон:Ref
|
||
Windows PowerShell | Шаблон:Code | «Invoke-Item »program arg1 arg2 ...
|
|
Bash shell | output=`command` or output=$(command)
|
Шаблон:Code |
Шаблон:Note Fortran 2008 or newer.[17]
References
- ↑ 1,00 1,01 1,02 1,03 1,04 1,05 1,06 1,07 1,08 1,09 1,10 1,11 1,12 1,13 1,14 1,15 Ada Reference Manual – Language and Standard Libraries; ISO/IEC 8652:201x (E), Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 4,0 4,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ 7,0 7,1 8.5 The Number Type
- ↑ 8,0 8,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web