Content deleted Content added
mNo edit summary |
TakuyaMurata (talk | contribs) need more and more |
||
Line 1:
This article describes the syntax of programming languages.
See [[comment]]
==== Loops ====▼
== Statements and blocks ==
The '''curly brace family''' of [[programming language]]s includes [[C programming language|C]], [[C Plus Plus|C++]], [[D programming language|D]], [[Java programming language|Java]], [[AWK]], [[Perl]], [[PHP]], [[C Sharp programming language|C#]] and others. The name derives from the common [[syntax]] of the languages, where blocks of statements are enclosed in [[bracket#Brackets in computing|curly braces]]. For example (using [[Berkeley Software Distribution|BSD]]/[[Eric Allman|Allman]] [[indent style]], one of many stylistic ways to format a program):
for (int i = 0; i < 10; i++)
'''{'''
printf("%d", i);
doTask(i);
'''}'''
Languages in this family are sometimes referred to as '''C-style''', because they tend to have syntax that is strongly influenced by [[C syntax|C's syntax]]. Beside the curly braces, they often inherit other syntactic features, such as using the semicolon as a statement terminator (not as a separator), and the three-part "for" statement syntax as shown above.
Generally, these languages are also considered "free-form languages", meaning that the compiler considers all whitespace to be the same as one blank space, much like [[HTML]]. Considering that, the above code ''could'' be written:
for(int i=0;i<10;i++)'''{'''printf("%d",i);doTask(i);'''}'''
but this is not recommended, as it becomes nearly impossible for a person to read after the program grows beyond a few statements.
There are many other ways to identify statement blocks, such as ending keywords that may match beginning keywords (see [[Visual Basic]], [[Pascal programming language|Pascal]], [[Ada programming language|Ada]], and [[REXX]]), indentation (see [[Python programming language|Python]]), or other symbols such as parentheses (see [[LISP]]).
In [[Java programming language|Java]], [[C programming language|C]] and [[C Plus Plus|C++]]
while (''Boolean expression'') {
''statement(s)''
}
do {
''statement(s)''
} while (''Boolean expression'');
for (''initialisation'' ; ''termination condition'' ; ''incrementing expr'') {
Line 19 ⟶ 40:
}
In [[Java programming language|Java]], [[C programming language|C]] and [[C Plus Plus|C++]]
▲==== Conditional statements ====
if (''Boolean expression'') {
''statement(s)''
}
if (''Boolean expression'') {
Line 32 ⟶ 52:
''statement(s)''
}
if (''Boolean expression'') {▼
''statement(s)''▼
switch (''integer expression'') {
Line 58 ⟶ 63:
}
In [[Ruby programming language|Ruby]],
end
=== Exception handling ===
In [[Java programming language|Java]], [[C programming language|C]] and [[C Plus Plus|C++]]
try {
''statement(s)''
Line 70 ⟶ 80:
''statement(s)''
}
[[Category:Curly bracket programming languages]]
|