top of page
06 Control Structures
if /else (conditional)
if(expression)
{
// statement(s)
}
else
{
// statement(s)
}
expression: a (boolean) C statement that evaluates to true or false
In this example an if else statement can be used to execute one code block if the condition is true and a second block if the condition is false
For example, an analog input could be tested and one action taken if the input was less than 500, and another action taken if the input was 500 or greater. else can proceed another if test, so that multiple, mutually exclusive tests can be run at the same time.The code would look like this:
bottom of page