I read the arduino help files on Curly Brackets but It is still un clear to me what they are for.
Seems you can use them to group things together but does not seem to be required.
What is the real use is the curly brackets?
int test1 = 10;
{
int test2 = 100;
test1 = test2 + 50; // Can access test1 here, it is in scope.
}
// cannot access test2 here, it is out of scope. test1 is equal to 150 here ...
Piolt34:
I read the arduino help files on Curly Brackets but It is still un clear to me what they are for.
Seems you can use them to group things together but does not seem to be required.
What is the real use is the curly brackets?
Curly brackets define a "code block".
For example:
If you create a for-loop, then only the NEXT COMMAND will be executed. Or the NEXT CODEBLOCK included in curly brackets.
Same with an if-condition: After an if-condition only the NEXT COMMAND will be executed. Or the NEXT CODEBLOCK included in curly brackets.
So curly brackets are putting together what belongs together.
Besides of that they define the beginning and ending of a function, which is the code which belongs to a function.