If a variable name contains more than one word, most c++ programmers use ____.

In computer programming, a statement is a syntactic unit of an imperative programming language that expresses some action to be carried out. A program written in such a language is formed by a sequence of one or more statements. A statement may have internal components (e.g., expressions).

Many programming languages (e.g. Ada, Algol 60, C, Java, Pascal) make a distinction between statements and definitions/declarations. A definition or declaration specifies the data on which a program is to operate, while a statement specifies the actions to be taken with that data.

Statements which cannot contain other statements are simple; those which can contain other statements are compound.

The appearance of a statement (and indeed a program) is determined by its syntax or grammar. The meaning of a statement is determined by its semantics.

Simple statements[edit]

Simple statements are complete in themselves; these include assignments, subroutine calls, and a few statements which may significantly affect the program flow of control (e.g. goto, return, stop/halt). In some languages, input and output, assertions, and exits are handled by special statements, while other languages use calls to predefined subroutines.

  • assignment
    • Fortran: variable = expression
    • Pascal, Algol 60, Ada: variable := expression;
    • C, C#, C++, PHP, Java: variable = expression;
  • call
    • Fortran: CALL subroutine name(parameters)
    • C, C++, Java, PHP, Pascal, Ada: subroutine name(parameters);
  • assertion
    • C, C++, PHP: assert(relational expression);
    • Java: DO WHILE (test) END DO 0
  • goto
    • Fortran: DO WHILE (test) END DO 1
    • Algol 60: DO WHILE (test) END DO 2
    • C, C++, PHP, Pascal: DO WHILE (test) END DO 3
  • return
    • Fortran: DO WHILE (test) END DO 4
    • C, C++, Java, PHP: DO WHILE (test) END DO 5
  • stop/halt/exit
    • Fortran: DO WHILE (test) END DO 6
    • C, C++: DO WHILE (test) END DO 7
    • PHP: DO WHILE (test) END DO 8

Compound statements[edit]

Compound statements may contain (sequences of) statements, nestable to any reasonable depth, and generally involve tests to decide whether or not to obey or repeat these contained statements.

Notation for the following examples:
  • is any single statement (could be simple or compound).
  • is any sequence of zero or more
Some programming languages provide a general way of grouping statements together, so that any singlecan be replaced by a group:
  • Algol 60: DO WHILE (test) END DO 9
  • Pascal: IF (test) THEN END IF 0
  • C, PHP, Java: IF (test) THEN END IF 1
Other programming languages have a different special terminator on each kind of compound statement, so that one or more statements are automatically treated as a group:
  • Ada: IF (test) THEN END IF 2

Many compound statements are loop commands or choice commands. In theory only one of each of these types of commands is required. In practice there are various special cases which occur quite often; these may make a program easier to understand, may make programming easier, and can often be implemented much more efficiently. There are many subtleties not mentioned here; see the linked articles for details.

  • count-controlled loop:
    • Algol 60: IF (test) THEN END IF 3
    • Pascal: IF (test) THEN END IF 4
    • C, Java: IF (test) THEN END IF 5
    • Ada: IF (test) THEN END IF 6
    • Fortran 90:

      DO index = 1,limit END DO

  • condition-controlled loop with test at start of loop:
    • Algol 60: IF (test) THEN END IF 7
    • Pascal: IF (test) THEN END IF 8
    • C, Java: IF (test) THEN END IF 9
    • Ada: IF (test) THEN ELSE END IF 0
    • Fortran 90:

      DO WHILE (test) END DO

  • condition-controlled loop with test at end of loop:
    • Pascal: IF (test) THEN ELSE END IF 1
    • C, Java: IF (test) THEN ELSE END IF 2
    • Ada: IF (test) THEN ELSE END IF 3
  • condition-controlled loop with test in the middle of the loop:
    • C: IF (test) THEN ELSE END IF 4
    • Ada: IF (test) THEN ELSE END IF 5
  • if-statement simple situation:
    • Algol 60:IF (test) THEN ELSE END IF 6
    • Pascal:IF (test) THEN ELSE END IF 7
    • C, Java: IF (test) THEN ELSE END IF 8
    • Ada: IF (test) THEN END IF 2
    • Fortran 77+:

      IF (test) THEN END IF

  • if-statement two-way choice:
    • Algol 60:variable = expression0
    • Pascal:variable = expression1
    • C, Java: variable = expression2
    • Ada: variable = expression3
    • Fortran 77+:

      IF (test) THEN ELSE END IF

  • case/switch statement multi-way choice:
    • Pascal: variable = expression4
    • Ada: variable = expression5
    • C, Java: variable = expression6
  • Exception handling:
    • Ada: variable = expression7
    • Java: variable = expression8
    • Python: variable = expression9

Apart from assignments and subroutine calls, most languages start each statement with a special word (e.g. goto, if, while, etc.) as shown in the above examples. Various methods have been used to describe the form of statements in different languages; the more formal methods tend to be more precise:

  • Algol 60 used Backus–Naur form (BNF) which set a new level for language grammar specification.
  • Up until Fortran 77, the language was described in English prose with examples, From Fortran 90 onwards, the language was described using a variant of BNF.
  • Cobol used a two-dimensional metalanguage.
  • Pascal used both syntax diagrams and equivalent BNF.

BNF uses recursion to express repetition, so various extensions have been proposed to allow direct indication of repetition.

Statements and keywords[edit]

Some programming language grammars reserve keywords or mark them specially, and do not allow them to be used as identifiers. This often leads to grammars which are easier to parse, requiring less .

No distinguished keywords[edit]

Fortran and PL/1 do not have reserved keywords, allowing statements like:

  • in PL/1:
    • variable := expression;0 (the second variable := expression;1 and the first variable := expression;2 are variables).
  • in Fortran:
    • variable := expression;3 conditional statement (with other variants)
    • variable := expression;4 assignment to a subscripted variable named variable := expression;1
As spaces were optional up to Fortran 95, a typo could completely change the meaning of a statement:
  • variable := expression;6 start of a loop with I running from 1 to 5
  • variable := expression;7 assignment of the value 1.5 to the variable variable := expression;8

Flagged words[edit]

In Algol 60 and Algol 68, special tokens were distinguished explicitly: for publication, in boldface e.g. variable := expression;9; for programming, with some special marking, e.g., a flag (variable = expression;0), quotation marks (variable = expression;1), or underlined (variable = expression;2 on the Elliott 503). This is called "stropping".

Tokens that are part of the language syntax thus do not conflict with programmer-defined names.

Reserved keywords[edit]

Certain names are reserved as part of the programming language and can not be used as programmer-defined names. The majority of the most popular programming languages use reserved keywords. Early examples include FLOW-MATIC (1953) and COBOL (1959). Since 1970 other examples include Ada, C, C++, Java, and Pascal. The number of reserved words depends on the language: C has about 30 while COBOL has about 400.

Semantics[edit]

Semantics is concerned with the meaning of a program. The standards documents for many programming languages use BNF or some equivalent to express the syntax/grammar in a fairly formal and precise way, but the semantics/meaning of the program is generally described using examples and English prose. This can result in ambiguity. In some language descriptions the meaning of compound statements is defined by the use of 'simpler' constructions, e.g. a while loop can be defined by a combination of tests, jumps, and labels, using variable = expression;3 and variable = expression;4.

The semantics article describes several mathematical/logical formalisms which have been used to specify semantics in a precise way; these are generally more complicated than BNF, and no single approach is generally accepted as the way to go. Some approaches effectively define an interpreter for the language, some use formal logic to reason about a program, some attach affixes to syntactic entities to ensure consistency, etc.

Expressions[edit]

A distinction is often made between statements, which are executed, and expressions, which are evaluated. Expressions always evaluate to a value, which statements do not. However, expressions are often used as part of a larger statement.

In most programming languages, a statement can consist little more than an expression, usually by following the expression with a statement terminator (semicolon). In such a case, while the expression evaluates to a value, the complete statement does not (the expression's value is discarded). For instance, in C, C++, C#, and many similar languages, variable = expression;5 is an expression that will set x to the value of y plus one, and the whole expression itself will evaluate to the same value that x is set to. However, variable = expression;6 (note the semicolon at the end) is a statement that will still set x to the value of y plus one because the expression within the statement is still evaluated, but the result of the expression is discarded, and the statement itself does not evaluate to any value.

Expressions can also be contained within other expressions. For instance, the expression variable = expression;5 contains the expression variable = expression;8, which in turn contains the values variable = expression;9 and CALL subroutine name(parameters)0, which are also technically expressions.

Although the previous examples show assignment expressions, some languages do not implement assignment as an expression, but rather as a statement. A notable example of this is Python, where = is not an operator, but rather just a separator in the assignment statement. Although Python allows multiple assignments as each assignment were an expression, this is simply a special case of the assignment statement built into the language grammar rather than a true expression.

Extensibility[edit]

Most languages have a fixed set of statements defined by the language, but there have been experiments with extensible languages that allow the programmer to define new statements.

What is variable in programming?

In programming, a variable is a value that can change, depending on conditions or on information passed to the program. Typically, a program consists of instruction s that tell the computer what to do and data that the program uses when it is running.

Where is a variable's data type or other information is stored as part of the name?

a variable-naming convention in which a variable's data type or other information is stored as part of its name. a variable's name.

When the first letter of a variable name is uppercase?

Pascal case requires that the first letter of a variable be in upper case. In contrast, camel case -- also known as CamelCase -- allows the first letter to be either upper or lower case. To clarify between the two options, the terms UpperCamelCase and lowerCamelCase are often used.

What is the name of a coding scheme that assigns a specific numeric code to each character on your keyboard?

ASCII, in full American Standard Code for Information Interchange, a standard data-encoding format for electronic communication between computers. ASCII assigns standard numeric values to letters, numerals, punctuation marks, and other characters used in computers.

Toplist

Neuester Beitrag

Stichworte