What are the use cases of using optional for loop statements?

pandaquests profile image pandaquests ・1 min read

I don't think any of them are good practice. In addition to that they make the code longer.

I fail to see the benefit of using optional statements in for-loops. But maybe I'm missing something? Could someone provide examples where the optional for-loop statement is superior to the standard for-loop?


markdown guide

Never done this before, but I could imagine a scenario where I'd want to break out of a loop half way through the iteration, if a condition is met. Then if that was the only way to break out, then omitting the condition makes sense to me.


Then just use an infinite loop, e g. While (true) { check condition }