Share your repls and programming experiences

← Back to all posts
No If Statements
SixBeeps (5232)

Your code has too many if statements.
I mean, sure, they are useful, but what if they weren't?

In reality, along with while loops, you don't really need if statements. All you need is the magical for-loop. You can completely replace all of your if statements with for loops, as shown in the Repl below.

The way it works is like this: the for loop takes in 3 arguments. The first one is for declaring the iteration variable(s), the second is for stating the condition for when to stop looping, and the third one does the iterating. Now, we don't need the first and third ones, so we can keep them blank. The second one, however, is where we'll put the condition for our "vegan" if statement. Finally, we need to work out the issue that keeping this on its own will cause everything to go in an infinite loop. Easy fix, we'll stick a break at the very end of the for loop.

So, our code should look something like this:

for (;condition;) {
  // do something
  break;
}

I hope you hate it.

Comments
hotnewtop
realTronsi (929)

I can't tell if this is a joke or not

xxpertHacker (935)

I mean, sure, they are useful, but what if they weren't?

Correction:

I mean, sure, they are useful, but what for(;they weren't?;) { break; }

Seems about right :D

SixBeeps (5232)

@xxpertHacker Gosh darn it, you have me there.

FlaminHotValdez (685)

You are absolutely correct. My mind has been blown. I will adopt this brilliant new method of coding.*

*Nice to see people like actual nice code instead of just games.

SixBeeps (5232)

@maxyang Yes, the for-loop shall rule over all other flow control.

LiamDonohue (294)

I am absolutely confused