Hide minor edits - Show changes to markup
if (i = 255) x = -1; // switch direction at peak
if (i == 255) x = -1; // switch direction at peak
int PWMpin = 10; // LED in series with 1k resistor on pin 10
int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10
Another example, fade an LED up and down with one 'for loop:
Another example, fade an LED up and down with one for loop:
'
Another example, fade an LED up and down with one for loop:
' Another example, fade an LED up and down with one 'for loop:
Another example, fade an LED up and down with one for loop:
Another example, fade an LED up and down with one for loop:
Another example, fade an LED up and down with one for loop:
void loop()
{
int x = 1;
for (int i = 0; i > -1; i = i + x){
analogWrite(PWMpin, i);
if (i = 255) x = -1; // switch direction at peak
delay(10);
}
}
For example using a multiplication in the increment line will generate a logarithmic progression:
For example, using a multiplication in the increment line will generate a logarithmic progression:
@@for(int x = 2; x < 100; x = x * 1.5){
[@for(int x = 2; x < 100; x = x * 1.5){
}@@
Generates:2,3,4,6,9,13,19,28,42,63,94
}@]
Generates: 2,3,4,6,9,13,19,28,42,63,94
For example using a multiplication in the increment line will generate a logarithmic progression.
for(int x = 2; x < 100; x = x * 1.5){
For example using a multiplication in the increment line will generate a logarithmic progression:
@@for(int x = 2; x < 100; x = x * 1.5){
}
}@@
The C for loop is much more flexible than for loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C statements with unrelated variables. These types of unusual for statements may provide solutions to some rare programming problems.
For example using a multiplication in the increment line will generate a logarithmic progression.
The C for loop is much more flexible than for loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C statements with unrelated variables, and use any C datatypes including floats. These types of unusual for statements may provide solutions to some rare programming problems.
For example using a multiplication in the increment line will generate a logarithmic progression.
for(int x = 2; x < 100; x = x * 1.5){
println(x);
}
Generates:2,3,4,6,9,13,19,28,42,63,94
The C for loop is much more flexible than for loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C statements with unrelated variables. These types of unusual for statements may provide solutions to some rare programming problems.
The C for loop is much more flexible than for loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C statements with unrelated variables. These types of unusual for statements may provide solutions to some rare programming problems.
For example using a multiplication in the increment line will generate a logarithmic progression.









void setup(){};
void loop(){};
for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}
int PWMpin = 10; // LED in series with 1k resistor on pin 10
void setup() {
// no setup needed
void loop() {
for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}
}
for (int i=1; i <= 8; i++){
// statement using the value i;
}
// Dim an LED using a PWM pin
void setup(){};
void loop(){};
for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}
}
#statement(s)
//statement(s);
statement using the value i;
// statement using the value i;
for (initialization;;condition;; increment) {
for (initialization; condition; increment) {
The initialization happens first and exactly once. Each time through the loop, the condition is tested; if it's true, the statement block, and the increment is executed, then the condition is tested again. When the condition is false, the loop ends.
The initialization happens first and exactly once. Each time through the loop, the condition is tested; if it's true, the statement block, and the increment is executed, then the condition is tested again. When the condition becomes false, the loop ends.
The initialization happens first and exactly once. Each time through the loop the condition is tested; if it's true, the statement block, and the increment is executed, then the condition is tested again. When the condition is false, the loop ends.
The initialization happens first and exactly once. Each time through the loop, the condition is tested; if it's true, the statement block, and the increment is executed, then the condition is tested again. When the condition is false, the loop ends.
The initialization happens first and exactly once. Each time through the loop the condition is tested; if it's true, the statement block, the increment is executed, and the condition is tested again. When the condition is false, the loop ends.
The initialization happens first and exactly once. Each time through the loop the condition is tested; if it's true, the statement block, and the increment is executed, then the condition is tested again. When the condition is false, the loop ends.
for (initialization; condition;increment) {
#statement(s)
for (initialization;;condition;; increment) {
#statement(s)
The initialization happens first and exactly once. Then, the condition is tested; if it's true, the body and the increment are executed, and the condition is tested again. When the condition is false, the loop ends.
The initialization happens first and exactly once. Each time through the loop the condition is tested; if it's true, the statement block, the increment is executed, and the condition is tested again. When the condition is false, the loop ends.
The C for loop is much more flexible than for loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C statements with unrelated variables. These types of unusual for statements may provide solutions to some rare programming problems.
for (initialization; condition;increment) {\\
#statement(s)\\
}
for (initialization; condition;increment) {
#statement(s)
}
for (initialization; condition; increment) {\\
for (initialization; condition;increment) {\\
Loops through multiple values, from the first to the last by the increment specified. Useful when used in combination with arrays to operate on collections of data/pins.
There are many parts to the for loop:
for (initialization; condition; increment) {
body
}
The for statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The for statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins.
There are three parts to the for loop header:
for (initialization; condition; increment) {\\
#statement(s)\\
}
Loops through the values of i, from the first to the last by the increment specified. Useful when used in combination with arrays to operate on collections of data/pins.
Important Note: In C you don’t need to initialise the local variable i. You can do it directly in the for statement itself. This is different in other, java based languages.
Loops through multiple values, from the first to the last by the increment specified. Useful when used in combination with arrays to operate on collections of data/pins.
There are many parts to the for loop:
for (initialization; condition; increment) {
body
}
The initialization happens first and exactly once. Then, the condition is tested; if it's true, the body and the increment are executed, and the condition is tested again. When the condition is false, the loop ends.
Important Note: In C you don’t need to initialise the local variable i. This is different in other, java based languages.
Important Note: In C you don’t need to initialise the local variable i. You can do it directly in the for statement itself. This is different in other, java based languages.
for (i=1; i <= 8; i++){
for (int i=1; i <= 8; i++){
Important Note: In C you don’t need to initialise the local variable i. This is different in other, java based languages.
Important Note: In C you don’t need to initialise the local variable i. This is different in other, java based languages.
[""Important Note:""] In C you don’t need to initialise the local variable i. This is different in other, java based languages.
Important Note: In C you don’t need to initialise the local variable i. This is different in other, java based languages.
"bold"Important Note:"bold" In C you don’t need to initialise the local variable i. This is different in other, java based languages.
[""Important Note:""] In C you don’t need to initialise the local variable i. This is different in other, java based languages.
<b>Important Note:</b> In C you don’t need to initialise the local variable i. This is different in other, java based languages.
"bold"Important Note:"bold" In C you don’t need to initialise the local variable i. This is different in other, java based languages.
for (i=1; i <= 8; i++) {
statement using the value i; }
N.B. In C you don’t need to initialise the local variable i. This is different in other, java based languages.
<b>Important Note:</b> In C you don’t need to initialise the local variable i. This is different in other, java based languages.
for (i=1; i <= 8; i++){
statement using the value i;
}
Loops through the values of i, from the first to the last by the increment specified. Useful when used in combination with arrays to operate on collections of data/pins.
for (i=1; i <= 8; i++) {
statement using the value i; }
N.B. In C you don’t need to initialise the local variable i. This is different in other, java based languages.