11

uni prof: "you can't make an infinite for loop. Infinite loopsnare only possible with while loops"....
I think it's not what he meant, but it was a while ago and I forgot the context, but multiple students made a 'what the fuck?' noise.

Comments
  • 4
    @LastDigitOfPi meh, too complex.
    At least in C++ you can do this
    for (;;) {}
  • 2
    @writeascript your prof may have been talking about for-each loops (eg. The for loop in Python). That's still not true in quite a few cases, eg. for looping over an infinite data structure, or an iterator that never ends.
  • 0
    @RememberMe Plus that this is the form from K&R, and also the only form of infinite loop that will pass Lint.
  • 0
    @LastDigitOfPi java checking in - not sure if other languages handle that differently, but as soon as i overflows the loop ends.
  • 4
    So. very. wrong.

    0) for(;;); // hello?
    1) for(i=0; i<12; i--); // incorrect iterators
    2) for(i=0; j<12; i++); // incorrect conditions
    3) for(i=0; i<12; i++) { i=0; } // modifying the accumulator within the loop
    4) for(i=0; i<12; ); // whoops!
    5) for(i=0; ; i++); // stolen condition
    6) for(i=0; i==0; i); // yawn.
    7) for(i=~3; ~i; i=~i); // infinite flopping nonsense ~

    Your instructor needs to stop attending/giving lectures and start coding again.
Add Comment