Forgo the usage of while loops
FlaminHotValdez (350)

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.

while(true){
  std::cout << "Hello World!" << std::endl;
}

Output:

Hello World!
Hello World!
Hello World!
...

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

for(;;){
  std::cout << "Hello World!" << std::endl;
}

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

while(condition){
  do something;
}
for(;condition;){
  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!

FOR LOOPS FOREVER!

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