Reference.For History

Hide minor edits - Show changes to output

December 23, 2013, at 11:49 AM by Cristian -Vacuum- Maglie - Fixed typo
Changed lines 3-4 from:
!!!!Desciption
to:
!!!!Description
January 31, 2011, at 03:11 PM by David A. Mellis -
Changed line 58 from:
if (i = 255) x = -1; // switch direction at peak
to:
if (i == 255) x = -1; // switch direction at peak
January 20, 2010, at 02:21 PM by Paul Badger -
Changed lines 23-24 from:
int PWMpin = 10; // LED in series with 1k resistor on pin 10
to:
int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10
January 14, 2010, at 04:15 PM by Paul Badger -
Changed lines 51-52 from:
Another example, fade an LED up and down with one '''for'' loop:
to:
Another example, fade an LED up and down with one '''for''' loop:
January 14, 2010, at 04:14 PM by Paul Badger -
Changed line 50 from:
'
to:
January 14, 2010, at 04:13 PM by Paul Badger -
Deleted line 14:
January 14, 2010, at 04:11 PM by Paul Badger -
Changed lines 51-53 from:

Another example, fade an LED up and down with one ''for'' loop:
to:
'
Another example, fade an LED up and down with one '''for'' loop:
January 14, 2010, at 04:08 PM by Paul Badger -
Changed lines 52-53 from:
Another example, fade an LED up and down with one for loop:
to:
Another example, fade an LED up and down with one ''for'' loop:
January 14, 2010, at 04:08 PM by Paul Badger -
Added lines 52-63:
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);
}
}@]
January 12, 2010, at 08:10 PM by Paul Badger -
Changed lines 44-45 from:
For example using a multiplication in the increment line will generate a logarithmic progression:\\
to:
For example, using a multiplication in the increment line will generate a logarithmic progression:\\
January 12, 2010, at 08:10 PM by Paul Badger -
Changed line 46 from:
@@for(int x = 2; x < 100; x = x * 1.5){
to:
[@for(int x = 2; x < 100; x = x * 1.5){
Changed lines 48-51 from:
}@@

Generates:2,3,4,6,9,13,19,28,42,63,94
to:
}@]

Generates: 2,3,4,6,9,13,19,28,42,63,94
January 12, 2010, at 08:09 PM by Paul Badger -
Changed lines 44-46 from:
For example using a multiplication in the increment line will generate a logarithmic progression.\\

for(int x = 2; x < 100; x = x * 1.5){
to:
For example using a multiplication in the increment line will generate a logarithmic progression:\\

@@for(int x = 2; x < 100; x = x * 1.5){
Changed lines 48-49 from:
}
to:
}@@
January 12, 2010, at 08:08 PM by Paul Badger -
Changed lines 42-45 from:
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.
to:
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
January 12, 2010, at 08:04 PM by Paul Badger -
Changed lines 40-43 from:
!!!!Coding Tip

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.
to:
!!!!Coding Tips

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.
January 12, 2010, at 08:02 PM by Paul Badger -
Changed lines 16-17 from:
%height=150px%Attach:ForLoopIllustrated.png
to:
%height=220px%Attach:ForLoopIllustrated.png
January 12, 2010, at 08:02 PM by Paul Badger -
Changed lines 16-17 from:
%height=250px%Attach:ForLoopIllustrated.png
to:
%height=150px%Attach:ForLoopIllustrated.png
January 12, 2010, at 07:58 PM by Paul Badger -
Deleted lines 8-11:
%height=250px%Attach:ForLoopIllustrated.png


Added line 11:
Added lines 16-17:
%height=250px%Attach:ForLoopIllustrated.png
January 12, 2010, at 07:56 PM by Paul Badger -
Changed lines 9-12 from:
Attach:ForLoopIllustrated.png


to:
%height=250px%Attach:ForLoopIllustrated.png


January 12, 2010, at 07:55 PM by Paul Badger -
Added lines 9-12:
Attach:ForLoopIllustrated.png


May 31, 2007, at 04:42 PM by David A. Mellis -
Changed lines 21-30 from:
#define PWMpin 10 // LED in series with 1k resistor on pin 10

void setup(){};

void loop(){};

for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}
to:
int PWMpin = 10; // LED in series with 1k resistor on pin 10

void setup()
{
// no setup needed
Added lines 27-34:

void loop()
{
for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}
}
Added line 36:
May 30, 2007, at 06:34 PM by Paul Badger -
Changed lines 21-22 from:
#define PWMpin 10
to:
#define PWMpin 10 // LED in series with 1k resistor on pin 10
May 30, 2007, at 06:33 PM by Paul Badger -
Changed lines 20-22 from:
for (int i=1; i <= 8; i++){
// statement using the value i;
}
to:
// Dim an LED using a PWM pin
#define PWMpin 10

void setup(){};

void loop(){};

for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}
}
April 17, 2007, at 12:00 AM by David A. Mellis -
Changed lines 11-12 from:
@@#statement(s)@@
to:
@@ //statement(s);@@
Changed line 21 from:
statement using the value i;
to:
// statement using the value i;
April 16, 2007, at 05:30 PM by Paul Badger -
Changed lines 9-10 from:
@@'''for''' ('''initialization;''';'''condition;''';''' increment''') {@@
to:
@@'''for''' ('''initialization''';''' condition''';''' increment''') {@@
Changed lines 15-16 from:
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.
to:
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.
April 16, 2007, at 05:27 PM by Paul Badger -
Changed lines 15-16 from:
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.
to:
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.
April 16, 2007, at 05:25 PM by Paul Badger -
Changed lines 15-16 from:
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.
to:
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.
April 16, 2007, at 05:21 PM by Paul Badger -
Changed lines 24-26 from:

!!!Coding Tip
to:
!!!!Coding Tip
April 16, 2007, at 05:21 PM by Paul Badger -
Changed lines 9-12 from:
@@for ('''initialization''';''' condition''';'''increment''') {@@

@@'''#statement(s)'''@@
to:
@@'''for''' ('''initialization;''';'''condition;''';''' increment''') {@@

@@#statement(s)@@
Changed lines 15-16 from:
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.
to:
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.
Added lines 25-28:
!!!Coding Tip

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.
April 16, 2007, at 05:03 PM by Paul Badger -
Changed lines 9-12 from:
@@for ('''initialization'''; '''condition''';'''increment''') {@@\\
@@ #statement(s)@@\\
@@ }@@
to:
@@for ('''initialization''';''' condition''';'''increment''') {@@

@@'''#statement(s)'''@@

@@}@@
April 16, 2007, at 04:59 PM by Paul Badger -
Changed line 9 from:
@@for ('''initialization'''; '''condition'''; '''increment''') {@@\\
to:
@@for ('''initialization'''; '''condition''';'''increment''') {@@\\
April 16, 2007, at 04:52 PM by Paul Badger -
Changed lines 3-10 from:
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''') { \\
&nbsp;&nbsp; '''body''' \\
}@@
to:
!!!!Desciption

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)@@\\
@@ }@@
April 16, 2007, at 04:36 PM by Paul Badger -
April 16, 2007, at 04:17 PM by Paul Badger -
April 16, 2007, at 04:16 PM by Paul Badger -
Changed lines 1-2 from:
!for statements
to:
!!for statements
April 16, 2007, at 04:16 PM by Paul Badger -
Deleted lines 23-24:

[[HomePage | Reference Home]]
December 02, 2006, at 04:53 PM by David A. Mellis -
Changed lines 13-14 from:
!!! Example
to:
!!!! Example
Added lines 21-24:
!!!!See also

* [[while]]
December 02, 2006, at 04:52 PM by David A. Mellis -
Changed lines 3-6 from:
to:
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''') { \\
&nbsp;&nbsp; '''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.
Deleted lines 20-27:







March 27, 2006, at 06:59 PM by Tom Igoe -
Changed lines 5-6 from:
to:
Changed line 10 from:
for (i=1; i <= 8; i++){
to:
for (int i=1; i <= 8; i++){
March 24, 2006, at 11:37 PM by Jeff Gray -
Changed lines 1-2 from:
!!for()
to:
!for statements
March 24, 2006, at 11:28 PM by Jeff Gray -
Changed lines 5-6 from:
to:
March 24, 2006, at 11:28 PM by Jeff Gray -
Changed lines 5-6 from:
to:
March 24, 2006, at 11:27 PM by Jeff Gray -
Changed lines 5-6 from:
to:
March 24, 2006, at 11:25 PM by Jeff Gray -
Changed lines 5-6 from:
to:
March 24, 2006, at 11:25 PM by Jeff Gray -
Added lines 1-2:
!!for()
Changed lines 5-10 from:
to:
February 14, 2006, at 04:50 PM by Erica Calogero -
Added lines 1-8:

Share