Tutorials/Arduino Projects/Additional Info/Loops
| (One intermediate revision by one user not shown) | |||
| Line 1: | Line 1: | ||
{{DISPLAYTITLE:Loops}} | {{DISPLAYTITLE:Loops}} | ||
| − | <yambe:breadcrumb self=" | + | <yambe:breadcrumb self="Loops">Tutorials/Arduino_Projects/Mobile_Robotics/BoeBot/How_to_Dim_an_LED|How to dim LEDs using the Arduino (BoeBot)</yambe:breadcrumb> |
| − | <yambe:breadcrumb self=" | + | <yambe:breadcrumb self="Loops">Tutorials/Arduino_Projects/Mobile_Robotics/VEX/How_to_Dim_an_LED|How to dim LEDs using the Arduino (VEX)</yambe:breadcrumb> |
| − | <yambe:breadcrumb self=" | + | <yambe:breadcrumb self="Loops">Tutorials/Arduino_Projects/Mobile_Robotics/Lego/How_to_Dim_an_LED|How to dim LEDs using the Arduino (Lego)</yambe:breadcrumb> |
| − | <yambe:breadcrumb self=" | + | <yambe:breadcrumb self="Loops">Tutorials/Arduino_Projects/Mobile_Robotics/Tetrix/How_to_Dim_an_LED|How to dim LEDs using the Arduino (Tetrix)</yambe:breadcrumb> |
| − | <yambe:breadcrumb self=" | + | <yambe:breadcrumb self="Loops">Arduino_Projects|Arduino Tutorials and Guided Projects</yambe:breadcrumb> |
{{tl|1|}} | {{tl|1|}} | ||
== While Loops == | == While Loops == | ||
{{Note|under construction.}} | {{Note|under construction.}} | ||
| + | While loops are a programming statement that is used to run a section of code multiple times. The while loop consists of a condition and a block of code. The condition is used to check if the block of code should be run again. As long as the condition evaluates to true, the block of code will run. | ||
| + | |||
| + | The code block is a group of programming statements that are enclosed in curly brackets ({}). This block of code can be made up of any statements. | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | while(condition) | ||
| + | { | ||
| + | //code to execute | ||
| + | }</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
<br /> | <br /> | ||
== For Loops == | == For Loops == | ||
{{Note|under construction.}} | {{Note|under construction.}} | ||
| + | For loops are a programming statement that is used to run a section of code multiple times. The for loop consists of an initialization section, a condition, an incrementer and a block of code. The initialization section sets a variable at a starting value. The condition is used to check if the loop should execute the block of code again. After every iteration of the loop, the incrementer will run. this is used to change the value of the variable from the initialization section. | ||
| + | |||
| + | The code block is a group of programming statements that are enclosed in curly brackets ({}). This block of code can be made up of any statements. | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | for(Initialization; Condition; incrementer) | ||
| + | { | ||
| + | //code to execute | ||
| + | }</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | For loops can be thought of as a partially configured while loop. | ||
| + | {| | ||
| + | |- | ||
| + | | | ||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | for(int i=0; i<10; i++) | ||
| + | { | ||
| + | //code to execute 10 times | ||
| + | }</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | | is equivalent to | ||
| + | | | ||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | int i=0; | ||
| + | while(i<10) | ||
| + | { | ||
| + | //code to execute 10 times | ||
| + | |||
| + | i++; | ||
| + | }</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
<br /> | <br /> | ||
[[Category:need to be finished]] | [[Category:need to be finished]] | ||
Latest revision as of 12:54, 30 July 2012
|
While Loops
While loops are a programming statement that is used to run a section of code multiple times. The while loop consists of a condition and a block of code. The condition is used to check if the block of code should be run again. As long as the condition evaluates to true, the block of code will run.
The code block is a group of programming statements that are enclosed in curly brackets ({}). This block of code can be made up of any statements.
while(condition) { //code to execute } |
For Loops
For loops are a programming statement that is used to run a section of code multiple times. The for loop consists of an initialization section, a condition, an incrementer and a block of code. The initialization section sets a variable at a starting value. The condition is used to check if the loop should execute the block of code again. After every iteration of the loop, the incrementer will run. this is used to change the value of the variable from the initialization section.
The code block is a group of programming statements that are enclosed in curly brackets ({}). This block of code can be made up of any statements.
for(Initialization; Condition; incrementer) { //code to execute } |
For loops can be thought of as a partially configured while loop.
|
is equivalent to |
|