Arduino Program Control Flow, Structure and Statements

We shall discuss arduino control flow, which spans control structures and control statements.

Quick Navigation

  • Arduino Control Flow
  • Arduino control structure and control statements
    • IF STATEMENT
    • ELSE STATEMENT
    • ELSE IF STATEMENT
    • For statement
      • For Loop Syntax
    • While Statement
    • Do While Statement
    • Switch Case Statement

Arduino Control Flow

Suffice it to say that realization of a good program lies on the use of program control flow. Arduino program is single threaded and sequential.

Single threaded means lines of codes are executed one code at a time, while sequential means onecode line is executed after another. This method of program execution can be referred to as “program control flow” as the name implies, we actually ‘mean how to control the flow of the arduino program.’

As stated above, the Arduino code executes sequentially one after the other down the code lines, however, situations may arise in a program where the program execution is expected to jump steps or return backwards even without getting to the last line of the code, even in situations like this, the rule of thumb is that the program flow must remain logical without errors.

To tackle such situations, we need to structure the program in such a way that the flow will be logical and error free using structural logical statements to control the program flow.

Arduino control structure and control statements

The control structure tells how the codes are organized to enable the program take actions based on certain conditions. Take for example; you want your program to turn on an LED only when a sensor recorded 50°C, you have to structure your code in such a way to execute such command accurately.

The method of ensuring such actions in a program can be seen as program control structuring, also known as “control structure”. This is seen especially when certain conditions are present in a program, just as the one stated above. In other to realize a smart and effective control structure in Arduino programming we use control statements.

Control statements are elements (functions) in a source code that control the flow of program execution, either to wait, jump, repeat, etc.

Arduino control statements include:

  • If statement
  • Else statement
  • Else if statement
  • For statement
  • While statement
  • Do while statement
  • Switch case
  • Continue

Protected Area

This content is password-protected. Please verify with a password to unlock the content.

With a sound knowledge of the various program control flow statements we can write different codes to execute different actions with ease.

End Of Post

Other episodes

error: Content is protected !!