31
pily
8y

First year at uni, during c++ basis.
The professor has just finished explaining the while cycle.
Professor: We want the code to print all numbers from 0 to 40 using a counter. How would you do?

Classmate puts up his hand: we do 40 if statements and when we reach the 40th one we stop.

Professor: *face palm*

Comments
  • 14
    Well, the loop is unrolled, should be faster now.
  • 7
    Give that man a Cookie
  • 3
    @qn0x noone seems to recognize renegades tbese days. Legit I once went totally unprepared to an assembly exam and wrote a no loop voting tally system. Of course it worked and of course he failed me but he said it made him laugh.
  • 1
    I had students I TA'd for insisting on using the while loop even after being introduced to for. So code like this wasn't uncommon:

    int i = 0;
    while (i < arraylength) {
    // do stuff with array
    i++;
    }

    It's as if they were either afraid of the for loop, or stated out with a while to see how it evolved and then never changed it
  • 0
    Well for always looked scary until we started using it! And once we did everyone knows there is no stop!
  • 0
    If you want to print out the numbers from 0 to 40 included it's easily to write it down into the for form...
    For(int i=0; i<40; i++){cout>>i;}

    Just to say... :)
  • 1
    @R1cc4rd0 that's a compiler error.
    It's cout << i
    🙃
  • 0
    @ElectricCoffee Ops... You're right... I always make that mistake 😅
  • 0
    @R1cc4rd0 it was pretty confusing to me at first, too
    And to an extent it kinda still is
Add Comment