[quote=“ivan, post:1, topic:3168, full:true”]
Welcome to the discussion about the reading assignment about Loops in C++.
Leave your answers to the questions below in this thread. If you have any questions or you want to discuss something connected to the assignment feel free to do it in this thread as well, but please everything to the topic.
Read this article (http://www.learncpp.com/cpp-tutorial/55-while-statements/ ).
Think about the following questions while reading:
1. What can we do with the while statement?
A while statement
is declared using the while keyword. When a while statement
is executed, the condition
is evaluated. If the condition evaluates to true
, the associated statement executes.
However, unlike an if statement
, once the statement has finished executing, control returns to the top of the while statement
and the process is repeated. This means a while statement
will keep looping for as long as the condition evaluates to true
.
2. What value needs the statement in the brackets evaluate to in order for the loop to continue?
True
3. What is an infinite loop?
If the while statement continues forever, it is an infinite loop.
if the expression always evaluates to true, the while loop will execute forever. This is called an infinite loop
4. What is an iteration?
Each time a loop executes, it is called an iteration.
At the bottom of the article you’ll see a quiz - make sure to do the quiz!
Read this article (http://www.learncpp.com/cpp-tutorial/57-for-statements/ ).
Think about the following questions while reading:
1. When is it a good idea to use a for statement (do a for loop) instead of the while loop we learned previously?
The for statement (also called a for loop) is preferred when we have an obvious loop variable because it lets us easily and concisely define, initialize, test, and change the value of loop variables
2. How would you write a for-loop in code?
for (init-statement; condition; end-expression)
statement
3. What is an off-by-one error?
Off-by-one errors occur when the loop iterates one too many or one too few times to produce the desired result.