Arduino Programming Language: For

Name

for

Description

The for statement is an iteratively control structure that determines the execution of a portion of the program repeated for a certain known number of times. 
The for statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins.

Syntax

for(initialization;test;increment) {
//statements
}

The initialization happens first and exactly once; in each iteration of the code , the variable is incremented until the test becomes false.

Parameters

  • initialization: statement executed once when beginning loop
  • test: if the test evaluates to true, the statements execute
  • increment: executes at the end of each iteration
  • statements: collection of statements executed each time through the loop

Usage

Application

Examples

// Dim an LED using a PWM pin
int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10

void setup() {
// no setup needed
}

void loop() {
for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}
}


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc