top of page

06 Control Structures

if /else (conditional)

Control Structure Comparison

if /else allows greater control over the flow of code than the basic if statement, by allowing multiple tests to be grouped together.

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:


© 2021 Odyssey Navigator. All rights reserved.

bottom of page