````

Arduino - Control Statements

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program. It should be along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
Following is the general form of a typical decision making structure found in most of the programming languages −
Decision Making
Control Statements are elements in Source Code that control the flow of program execution.
 They are −

1-Arduino - If statement

It takes an expression in parenthesis and a statement or block of statements. If the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.

Different forms of if statement

Form 1
if (expression)
   statement;
You can use the if statement without braces { } if you have one statement.
Form 2
if (expression) {
   Block of statements;
}

if Statement – Execution Sequence

IF Statement

Example

/* Global variable definition */
int A = 5 ;
int B = 9 ;

Void setup () {

}

Void loop ()
 {
   /* check the boolean condition */
   if (A > B)
 /* if condition is true then execute the following statement*/
   A++;
   /* check the boolean condition */
   If ( ( A < B ) && ( B != 0 ))
 /* if condition is true then execute the following statement*/ 
{ 
      A += B;
      B--;
   }
}

 

Related Posts:

  • Microcontrollers 8051 Input Output Ports 8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input or output. Hence, total 32 input/output pins allow the microcontroller to be connected with the peripheral devices. Pin configuration,… Read More
  • What is power electronics? Normal 0 false false false EN-US X-NONE X-NONE … Read More
  • Microcontrollers - 8051 Pin Description The pin diagram of 8051 microcontroller looks as follows − Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other functions. It is internally pulled up, bi-directional I/O port. Pin 9 − It is a … Read More
  • Microcontrollers - 8051 Interrupts Microcontrollers - 8051 Interrupts Interrupts are the events that temporarily suspend the main program, pass the control to the external sources and execute their task. It then passes the control to the main program whe… Read More
  • 555 Timer PWM Audio Amplifier The ubiquitous 555 timer IC handles audio signals in its own pulse-width modulation (PWM) way. Here, the 555 IC works in astable mode. The switching frequency can be varied from 65 kHz to 188 kHz. Selection of PWM frequen… Read More

0 comments:

Post a Comment

 
Powered by Blogger