Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Why use a ‘while’ loop instead of a ‘for’ loop ? 2) Why use a ‘do while’ loop

ID: 3709122 • Letter: 1

Question

1) Why use a ‘while’ loop instead of a ‘for’ loop ?

2) Why use a ‘do while’ loop ? General answer.

3) What is the syntax for the ‘do while’ loop ?

4) Are there other types of loops in C++, besides ‘for’, ‘while’ and ‘do whiles’ ? If so, what are they ?

5) Why use a loop ? What are the alternatives ?

6) What is difference between pretest and posttest loops ?

7) Can you have two loop statements overlap, or must they be nested ?

8) What is an Infinite loop ?

9) Would your boss like to you to copy and paste statements or write them once and use in a loop ?

10) What is your favorite loop… why ?

Explanation / Answer

NOTE: Acoording to the chegg policy we can't do the above of 4 questions but here I am giving you the 5 answers.But you can repost your remaining questions.

ANSWER 1: A for loop runs for a pre-determined number of times. So, it can iterate through an array from start to finish, say, but it will only ever loop for that specific number.

A while loop will carry on until a pre-determined scenariotakes place. That may happen immediately, or it may require a hundred iterations. So, the number of loops is governed by an outcome, not a number. For example, you can continue looping until the user presses the Z key (while keyPressed != 'Z') - the loop will constantly run until that happens. It may never happen.

A for loop has it's bounds set from the beginning and, yes, while you can manipulate those bounds, the general implementation is such that the maximum number of loops is pre-determined.

ANSWER 2: The do ... while loop ensures that the body of the loop executes at least once,that 's why we use do...while loop other wise it is a simple loop like for and while.

ANSWER 3: do...while loop Syntax :

ANSWER 4: Other than this following are the loops:

(a): for_each loop:

Syntax of for_each

for_each applies function fn for each element in the range starting from first to last.

EXAMPLE:

The output of above code will be

11  21  4  13
11  21  4  13

ANSWER (5): Loops have its own importance and there is no alternative for the loops to do the task repeadly. Some times recursion can do the same task but it has it's depandancies.