Consider yourself lucky that there was an "else", because if not, it would compile as legal code but the statement would do nothing. Then you'd really be wondering what is going on.
aarg:
Consider yourself lucky that there was an "else", because if not, it would compile as legal code but the statement would do nothing. Then you'd really be wondering what is going on.
I just had this "issue" myself not to long ago. I spend hours debugging the code because I overlooked the semicolon. What is the function for allowing a semicolon in the if statement? Do you think it's a good choice to allow it in the Arduino language?
Lennyz1988:
I just had this "issue" myself not to long ago. I spend hours debugging the code because I overlooked the semicolon. What is the function for allowing a semicolon in the if statement? Do you think it's a good choice to allow it in the Arduino language?
It's not embedded in the "if" syntax in particular. The reason is that C was designed for code brevity. Whether it is a good choice is a question you would have had to ask Kernighan and Ritchie, back around 1969.
Lennyz1988:
What is the function for allowing a semicolon in the if statement? Do you think it's a good choice to allow it in the Arduino language?
First, it's not "the Arduino language", it's industry-standard c++, which has existed since the late 1980's. Second, there are countless things you can do in ANY programming language that will not give the result you think they will. Just because code compiles, does not mean it performs the intended function. Otherwise, why would the word "debugging" even exist? One must take the time to LEARN a programming language, and not just start writing code without understanding the syntax. Becoming competent in ANY programming language requires the user investing both time and effort, exactly as one would to learn a foreign language. If you were learning French, would you start by questioning the wisdom of the French vocabulary and syntax before becoming expert in speaking it?
Regards,
Ray L.
What is the function for allowing a semicolon in the if statement? Do you think it's a good choice to allow it in the Arduino language?
The first thing to note is that there is no such thing as the "Arduino language". There is CC++ with arduino extensions provided by libraries.
If something is allowed in C and/or C++ then it will be allowed in the Arduino environment. If you do something stupid but it is still valid C code then the compiler will not complain. There are literally hundreds (thousands !) of ways of writing valid code that does not do what you want.
would you start by questioning the wisdom of the French vocabulary and syntax before becoming expert in speaking it?
I wouldn't question the wisdom of the vocabulary or syntax, but I might question the rules regarding the vocabulary or syntax.
To me, it would be part of the process of learning. Why does the plural of this word end in s, while the plural of that word does not? Knowing why allows one to make an educated guess about what the plural of a different word would be.