Arduino Programming Language: Braces

Name

{} curly braces

Description

The curly braces {} indicate the start and the finish of functions and statements blocks. 
They are also used to define the initial values in array declarations. 
An opening curly brace "{" must always be followed by a closing curly brace "}". This is a condition that is often referred to as the braces being balanced. 
Because the use of the curly brace is so varied, it is good programming practice to type the closing brace immediately after typing the opening brace when inserting a construct which requires curly braces.

Syntax

The main uses of curly braces: 

Functions:

void myfunction(datatype argument){
statements(s)
}

Loops:

while (boolean expression)
{
statement(s)
}

do
{
statement(s)
} while (boolean expression);

for (initialisation; termination condition; incrementing expr)
{
statement(s)
}

Conditional statements:

if (boolean expression)
{
statement(s)
}

else if (boolean expression)
{
statement(s)
}
else
{
statement(s)
}

Parameters

  • statements: something inside a block;
  • elements: {ele0, ..., eleN} : list of elements separated by commas

Usage

Application

Examples

int array[] ={3, 6, 9, 12, 15};

Related Functions


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc