Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I usually code for-loops with optional break upon early completion, otherwise while-loops. Very rarely do-while-loops. No issues with any of them.
-
Wack61955y@josap do you realize, that your first and second code snipets aren't equal?
The secend one isn't a while but a do-while loop.
While:
while (condition) {
doStuff();
}
Or using recursion
function myWhile() {
if (condition) {
doStuff();
myWhile();
}
}
On the otherhand a do-while is something like
do {
doStuff();
} while (condition);
Or using recursion
function myDoWhile() {
doStuff();
if (condition) {
myDoWhile();
}
}
Note: a do while loop executes at least once, as it only checks the condition after executing it's body. A while loop in the other hand first checks for the condition to hold and only executes if so.
Related Rants
Maybe it's just me, but:
1. Never works on first try:
doStuffWithWhile()
while (someShitIsNotOver)
doShit()
2. Works like a charm:
doStuffWithManualLoop()
doShit()
if (someShitIsNotOver)
doStuffWithManualLoop()
rant
loops
feeling stupid
bugs
while loops
while