67
Adroit
8y

My little sister was ranting about a punishment she got from her teacher. I told her to write this instead...Was this the wrong thing to do or it's just me... :P

Comments
  • 18
    count=0;count<500

    Other than that perfect
  • 3
    @jckimble lol..just so that she doesn't comes back to me asking "why counting from zero?" 😝
  • 2
    I think what you did could potentially inspire her to learn programming. It kinda did for me, but those days we used to actually write in actual paper.
  • 1
    @HoloDreamer Yeah..I told her to write this on that paper instead 😛
  • 0
    You forgot to add your little sister's handwritten fonts for the output.
  • 2
    @ekkapob I didn't ask her to run and take the output..I asked her to write this code on paper and just take that 😝
  • 0
    >.<
  • 2
    @mpotratz Simpsons did it first
  • 0
    No, this was the right thing to do.
  • 1
    Very wrong of you. That curly brace is ugly on the same line as the for loop.
  • 2
    @BartBB I disagree, that's what gives it a class.
  • 0
    Each his own opinion, I guess. @Adroit
  • 3
    If I were a teacher I'd reward the first student who did it for being creative but then in class demonstrate the solution and that anyone handing in the same solution would not be rewarded.

    If however they used a different language or say a while loop, I would reward that.

    Redeemed by creativity, further punished by simply copying another student.
  • 0
    @nmunro You'd be a good teacher 👌🏼
  • 0
    Actually, the following is slightly more performant:

    for (count = 500; count > 0; --count)
  • 0
    @Rocco care to explain?
  • 0
    @Rocco @Adroit ive heard that also. I've never done tests on it personally but i wonder why
  • 2
    @jckimble @adroit It goes down to how it is handled on the processor / in assembler. Compare against zero is a standard operation. For other values the value must first be loaded into a registry and then the compare is done against the registry value.
    Nowadays the effect is probably neglectable, but in the old days it could make a difference.
  • 0
    @Rocco I don't think it should affect much today considering the branch prediction schemes we have today, moreover branch target buffer will make it behave as good as comparing with zero. Caching is the best thing that has happened to us :)
  • 1
    Technically, *I shall
Add Comment