Control Structure
Similar to many other languages on Arduino we have control structures, some of this structure are:
From this the new one (in comparison with python and swift ) will be the goto
.
As other language we have ways to jump to return a value, go to the next item, or break the loop all together, for those task we have:
I won't add much about break
, continue
, and return
since they work like in another languages, same as some of the control structures. Although, I will add the syntax of some of those items, to quick reference.
do...while¶
Work similar to while
loop, with the exception the condition is evaluated at the end of the loop, so the loop aways run at least one time.
Syntax
Example
while¶
Like any other while loop, i will loop until the condition become False
Syntax
Exampleswitch...case¶
"switch case controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions"
var
: a variable whose value to compare with various cases. Allowed data types:int
,char
.label1
,label2
: constants. Allowed data types:int
,char
.
Syntax
goto¶
Transfers program flow to a labeled point in the program.
Syntax
Example
The use of goto is discouraged in C programming