3
josap
5y

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()

Comments
  • 1
    Growing stack like that? Doomed to fail :/
  • 0
    Kill it with fire
  • 0
    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.
  • 1
    @netikras not if you have reliable tail call optimization
  • 1
    @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.
  • 0
    @Wack yes, I do
Add Comment