diff --git a/education/software development/ECE1400/Chapter 6 Exercises.md b/education/software development/ECE1400/Chapter 6 Exercises.md index 3c141b4..ddd8f47 100644 --- a/education/software development/ECE1400/Chapter 6 Exercises.md +++ b/education/software development/ECE1400/Chapter 6 Exercises.md @@ -39,5 +39,20 @@ Output: > 4. Which one of the following statements is not equivalent to the other two (assuming that the loop bodies are the same?) ```c -(a) for (i = 0; i < 10) -``` \ No newline at end of file +for (i = 0; i < 10; i++) // (a) +for (i = 0; i < 10; ++i) // (b) +for (i = 0; i ++ < 10; ) // (c) +``` + +Answer: +C is not the same as A and B, because the increment takes place before the loop body is executed. + +> 5. Which one of the following statements is not equivalent to the other two (assuming that the loop bodies are the same)? +```c +while (i < 10) {...} // (a) +for (; i < 10;) {...} // (b) +do {...} while (i < 10); // (c) +``` + +Answer: +C is not the same as A and B, because the block is executed before the condition is checked. \ No newline at end of file