Structure -- Syntax
Let's learn about the syntax of Arduino programming. Syntax is very important, for if you were to put in the wrong syntax in your program, the Arduino Compiler will recognize it and will not run the program. Let's look at the basic syntax. Don't worry on what the functions may be. We are just focusing on the syntax.
x=123;
Here's our syntax: the semicolon. A semicolon is used to end a statement.
Here's another example. Tell me what's wrong with the code.
{
//some code goes here
If you guessed there's a missing bracket, you are correct. When using brackets, you need to open it, and close it {}.
Now for syntax in comments...
//comment
comment
There is a syntax error here in the comment. The // symbol only refers to one line for comments. Therefore, the comment that does not have a // before will result in a syntax error. There are two correct ways to do this. Here's the first:
//comment
//comment
To make things easier (for multi-line comment), we can use /* and */. These symbols work just like brackets, just that it's for comments. Here's an example.
/*
Dan-Robotics
*/
There. Now the compiler will count Dan-Robotics as part of a comment, therefore not producing a syntax error.
x=123;
Here's our syntax: the semicolon. A semicolon is used to end a statement.
Here's another example. Tell me what's wrong with the code.
{
//some code goes here
If you guessed there's a missing bracket, you are correct. When using brackets, you need to open it, and close it {}.
Now for syntax in comments...
//comment
comment
There is a syntax error here in the comment. The // symbol only refers to one line for comments. Therefore, the comment that does not have a // before will result in a syntax error. There are two correct ways to do this. Here's the first:
//comment
//comment
To make things easier (for multi-line comment), we can use /* and */. These symbols work just like brackets, just that it's for comments. Here's an example.
/*
Dan-Robotics
*/
There. Now the compiler will count Dan-Robotics as part of a comment, therefore not producing a syntax error.