Forgo the usage of while loops
FlaminHotValdez (356)

While loops have grown to become a staple ingredient in our codes. We use it for a lot of purposes.

Some Common Uses Of While Loops

  • Binary search
  • While-true loop
  • Basically anything that requires "Execute this code as long as this is true or this is not true."

It has a lot of uses.

But, we also have the for loop.

It does the exact same thing.

Allow me to demonstrate.

  std::cout << "Hello World!" << std::endl;


Hello World!
Hello World!
Hello World!

But this code does the exact same thing with a for loop.

  std::cout << "Hello World!" << std::endl;

But what about while loops that don't use the while-true statement?

  do something;
  do something;

See? There is absolutely no reason to use while loops.

I urge you all to stop using this redundant function and instead switch to a much simpler style of coding that only has one loop, the for loop that will always be dominant!


Unless you use Python. Then you suck you are uncultured you should stop using python while loops are useful.
You are viewing a single comment. View All
Coder100 (15550)

no, that isn't it, for loops desugar to

int i = 0;

while (i < 5) {
  // ... code ...