2

It's so easy to use for-each loops instead of if-else chains, yet when I write a system in for the first time, I always find myself doing the latter.

"It's placeholder code" saves me every time as long as I rewrite it later.

Comments
  • 2
    In what scenario is a conditional substitute for a loop?
  • 2
    @lbfalvy

    I imagine something like this:

    int sumOfValues(values [1, 2, 3, 4]) {

    int sum = 0;

    if 1 >= values.length(): sum += values[0];

    if 2 >= values.length(): sum += values[1];

    if 3 > =values.length(): sum += values[2];

    if 4 >= values.length(): sum += values[3];

    if 5 >= values.length(): sum += values[4];

    ...

    if 100 >= values.length(): sum += values[99];

    return sum;

    }
  • 2
    @lambda123 not sure what you mean that's my code from a production ready project. Im a senior with 50 years of experience!
  • 0
  • 2
    @Hazarth 30 of those were spent writing this single masterpiece
Add Comment