Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:programming_fundamentals_rtu:looping [2018/01/24 08:55] Agrisniken:iot-open:programming_fundamentals_rtu:looping [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 44: Line 44:
  
 <code c> <code c>
-int inputVariable = 0;+int inputVariable = analogRead(2);
 while (inputVariable < 100) while (inputVariable < 100)
 { {
Line 59: Line 59:
  
 ===== Do while ===== ===== Do while =====
 +//Do while// cycle works the same way like the //while// loop. The difference is that in the //while// cycle the condition is checked before entering the loop, but in the //do while// cycle the condition is checked after execution of the statements in the loop and then if the condition is //TRUE// the loop repeats. As the result, the statements inside the cycle will execute at least once, even if the test condition is //FALSE//.
  
 +The construction of a //do while// cycle is the following:
 +<code c>
 +do {
 +  //the body of the cycle
 +} while (condition that is TRUE);
 +</code>
 +
 +If the same code is taken from the //while// loop example and used in the //do while// cycle, the difference is that the code will execute at least once, even if the //inputVariable// value is more than or equal to 100. The example code:
 +<code c>
 +int inputVariable = analogRead(2);
 +do {
 +    digitalWrite(13, HIGH);
 +    delay(10);
 +    digitalWrite(13, LOW);
 +    delay(10);
 +    inputVariable = analogRead(2);
 +} while (inputVariable < 100);
 +</code>
 +
 +**Check yourself**
 +
 +1. What loop where the condition is checked after the loop body is executed?
 +
 +2. How long will the operators in the body of the loop will operate (while (x < 100))?
 +
 +3. What value will be for variable //a//  after code executing <code C> int a; for(a = 0; a < 10; a++) {} </code>
 +
 +4. Which of the following operators are not loop(s) in Arduino IDE?
 +  * do while
 +  * while
 +  * repeat until
 +  * for
  
en/iot-open/programming_fundamentals_rtu/looping.1516784129.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0