;
Description
Used to end a statement.
Example Code
※ NOTES AND WARNINGS:
Forgetting to end a line in a semicolon
Forgetting to end a line in a semicolon will result in a compiler error. The error text may be obvious, and refer to a missing semicolon, or it may not. If an impenetrable or seemingly illogical compiler error comes up, one of the first things to check is a missing semicolon, in the immediate vicinity, preceding the line at which the compiler complained.
#define and #include
The semicolon MUST NOT places after #define and #include
if/else statement and for/while loop
If a semicolon is placed right after an if statement, else statement, for loop, or while loop, the semicolon is equivalent to a empty {} (curly braces). It means code inside these statements/loops become outside of the statements/loops. Let see two examples of without and with semicolon.
- Without semicolon
- With semicolon
As we can see, with semicolon the code inside if statement is executed although the condition of the statement is false.
In more detail, the code with semicolon:
is equivalent to:
See Also
- Language : /* */ (block comment)
- Language : {} (curly braces)
- Language : #define (define)
- Language : #include (include)
- Language : // (single line comment)
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Additionally, some links direct to products from our own brand, DIYables.