160
Comments
  • 4
    Rolls off the tongue
  • 32
    this can be a nice advertisement slogan for durex or viagra
  • 3
    @CurseMeSlowly πŸ˜‚πŸ˜‚πŸ˜‚
  • 5
    @illusion466 if you're repeating the same code two or more times in a block, you should write a for statement.
  • 12
    @illusion466 pretty basic advice that one of my first teachers gave to the whole class, and it's being in my head ever since.

    Funny thing is, I haven't written a for statement in a long while (pun intended), I use map and reduce most times.

    Anyway, this reminds me that tedious, repeated work can be automated, and has driven me to write a lot of scripts that have saved me (and my coworkers) quite some time.
  • 6
    More than that, think of map πŸ˜‹
  • 1
    @rEaL-jAsE pffft. Triple digits and never charged... does that just make me a bad whore?
  • 2
    @aerfromenes keep in mind monadic bind?
  • 0
    Break from a nested loop, use a goto. πŸ”₯
  • 0
    @Bitwise style? How would you do it else?
  • 0
    @Sagi02 yeah, unless you are writing rust and have nice loop anotations
  • 0
    @Bitwise iirc languages like js, java, c, python, or c++ CAN break out of one loop, but not multiple nested loops without using a flag:

    for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
    printf("i: %i j: %i", i, j);
    if (i == 7) {
    goto END;
    }
    }
    }

    END:whatever

    Is much cleaner imho than

    int flag = 0;

    for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
    printf("i: %i j: %i", i, j);
    if (i == 7) {
    flag = 1;
    break;
    }
    }
    if (flag == 1) {
    break;
    }
    }

    Just a matter of opinion and circumstances.
    I don't know for other languages, but for C I'm pretty sure that's the idiomatic way to do it.
  • 0
  • 2
    @Sagi02 You could use that flag on the for's condition:

    int done = 0;
    for (int i = 0; i < 10 && !done; i++) {
    for (int j = 0; j < 10 && !done; j++) {
    // whenever you want to break:
    done = 1;
    }
    }
  • 2
    @shellbug that's clever, never tought about that... It must be because I program for good old sh3 30Mhz processor that shit themselves each time they must branch XD
  • 0
    @shellbug These are the best type of scripts. Especially when they can be hacked together with ducktape and toothpick types of fixes! Lots of time and mistakes can be saved in the end too.
Add Comment