This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bok:sw:cpp:main [2021/06/20 15:35] anwlur created |
bok:sw:cpp:main [2021/08/12 01:27] (current) anwlur [if ... else] |
||
---|---|---|---|
Line 25: | Line 25: | ||
==== bool ==== | ==== bool ==== | ||
- | bool boolSomeBoolean; | + | bool boolSomeBoolean; |
+ | |||
+ | Can be initialized with... | ||
+ | |||
+ | bool boolSomeBoolean1 = false; | ||
+ | bool boolSomeBoolean2 = 1; | ||
===== Functions ===== | ===== Functions ===== | ||
Line 54: | Line 59: | ||
</code> | </code> | ||
+ | A shorthand is available for simple if...else statements | ||
+ | <code cpp> | ||
+ | variable = (condition) ? trueStatement : falseStatement; | ||
+ | </code> | ||
+ | |||
+ | E.g. | ||
+ | <code cpp> | ||
+ | variable = ( today == birthday ) ? "Happy Birthday" : "Good day!"; | ||
+ | </code> | ||
+ | ==== for ==== | ||
+ | <code cpp> | ||
+ | for(int i = 0; i < limit; i++) { | ||
+ | statement; | ||
+ | } | ||
+ | </code> | ||
==== Boolean Operators ==== | ==== Boolean Operators ==== | ||
- | && -> logical AND | + | && // logical AND |
- | || -> logical OR | + | || // logical OR |
- | ! -> logical NOT | + | ! // logical NOT |
+ | |||
+ | ==== Compound Operators ==== | ||
+ | ^= // compound bitwise XOR | ||
+ | += // compound addition | ||
+ | -= // compound substraction | ||
====== C++ for Arduino ====== | ====== C++ for Arduino ====== | ||