Curly bracket programming language: Difference between revisions

Content deleted Content added
Statements and blocks: Changed word "braces" to "brackets" to conform to Wiki-usage.
Dexbot (talk | contribs)
m Bot: Fixing broken section link
Tag: Redirect target changed
 
(164 intermediate revisions by more than 100 users not shown)
Line 1:
#REDIRECT [[List of programming languages by type#Curly bracket languages]]
'''Curly brace''' or '''bracket''' [[programming language]]s are those which use [[balance]]d [[Bracket|bracket]]s ('''{''' and '''}''') in their [[syntax]] or [[formal grammar]], mainly due to being [[C programming language|C]]-influenced.
 
{{Redirect category shell|1=
== Statements and blocks ==
{{R to section}}
 
}}
The name derives from the common syntax of the languages, where blocks of statements are enclosed in curly braces or brackets. 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 brackets, 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 [[Ada programming language|Ada]], [[Pascal programming language|Pascal]], [[REXX]], and [[Visual Basic]]), indentation (see [[Python programming language|Python]]), or other symbols such as parentheses (see [[Lisp]]).
 
=== Loops ===
 
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'') {
''statement(s)''
}
 
=== Conditional statements ===
 
In [[Java programming language|Java]], [[C programming language|C]] and [[C Plus Plus|C++]]
if (''Boolean expression'') {
''statement(s)''
}
 
if (''Boolean expression'') {
''statement(s)''
} else {
''statement(s)''
}
 
switch (''integer expression'') {
case ''constant integer expr'':
''statement(s)''
break;
...
default:
''statement(s)''
break;
}
 
In [[Ruby programming language|Ruby]],
if ''expression'' then
''statement(s)''
end
 
=== Exception handling ===
 
In [[Java programming language|Java]] and [[C Sharp programming language|C#]]:
try {
''statement(s)''
} catch (exception type) {
''statement(s)''
} catch (exception type) {
''statement(s)''
} finally {
''statement(s)''
}
 
[[C Plus Plus|C++]] does not have <tt>finally</tt>, but otherwise looks similar.
[[C programming language|C]] has nothing like this, though some compilers vendors added the keywords <tt>__try</tt> and <tt>__finally</tt> to their implementation.
 
==Languages==
*[[C programming language|C]]
*[[C Plus Plus|C++]]
*[[C Sharp|C#]]
*[[Coyote programming language|Coyote]]
*[[Cyclone programming language|Cyclone]]
*[[D programming language|D]]
*[[Dino programming language|DINO]]
*[[E programming language|E]]
*[[ECMAScript]] a.k.a. [[JavaScript]], [[JScript]]
*[[Frink]]
*[[Java programming language|Java]]
*[[Perl]]
*[[PHP]]
*[[Pico programming language|Pico]]
*[[Pike_programming_language|Pike]]
*The [[Unix shell]]s: [[AWK programming language|AWK]], [[C shell]] (csh)
 
[[Category:Curly bracket programming languages|*]]