Similar Posts

Subscribe
Notify of
7 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Bushmills145
1 year ago
  • Starting a while loop is more complicated to type: 5 characters versus 3 characters
  • “for” can also be tapped more liquid, since on a QWERT[YZ] keyboard the fingers of the left, right and left hand are involved.
  • It is an advantage that for has the abovementioned advantages.
  • Suitable choice of running variables makes it possible to make code more human: “for now …” doesn’t sound much better than “while now”, or compare “for the_record” with “while the_record” – so code can be removed.
  • And finally, a for loop is useful in situations where a while loop is less suitable.
Destranix
1 year ago

Isn’t that so nonsense the question?

There is also no switch loop, but only a switch stage.

Perhaps better structuring, but that was dnan too.

Gehilfling
1 year ago

Advantage over what?

Compared to a “While” loop, you can define the start value and increment step directly and do not have to do this through your own constructs within.

TUrabbIT
1 year ago

A for loop makes sense when it comes to making a certain number of iterations. The number can also be determined at runtime, such as the number of elements in a list. Here is their advantage if one wants to withstand a while or do-while loop that the number of iterations is already fixed in the loop head.

A while loop makes sense if there is no firmness of how many iterations are needed, as this depends on a condition that occurs at an unknown time.

A do-while loop makes sense in the same case as the while loop, with the difference that in any case at least one iteration should be performed. (e.g. because the condition can only be checked)

A switch block has nothing to do with a loop and has another purpose.

If you want, you can still compare with a GO-TO loop.

In summary:

The different loops have different applications in which they have their strength, but no general advantages over other loops

wunschname0302
1 year ago

So a switchGrinding is unknown at first sight. The rest can be discounted. :

verreisterNutzer
1 year ago
Reply to  wunschname0302

Jup, me too. =D switch has nothing to do with grinding

Bernhard35
1 year ago

Advantages you need a comparison.

What properties do you want to compare?