// First Answers
1- while
allows a piece of code to execute repeatedly until given condition within the while statement is met.
while (condition) {
statement;
}
2- While statement is repeated until the condition is false, so it repeats while the value is true.
3- If the expression always evaluates to true, the while loop will execute forever.
4- Each time a loop executes, it is called an iteration.
// Second Answers
1- When there is an exact number of iteration, we can use for
loop. If the iteration number is undefined, we can use while
.
2-
`for (init-statement; condition; end-expression)`
` statement`
for (int count{ 1 }; count <= 10; ++count)
std::cout << count << ' ';
1 2 3 4 5 6 7 8 9 10
3- Off-by-one errors occur when the loop iterates one too many or one too few times to produce the desired result. For example ; using the wrong relational operator, using pre-increment or pre-decrement instead of post-increment or post-decrement, or vice-versa.