Forgo the usage of while loops
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!
no
that is completely false
which one looks better?
also,
for
loops literally are while loops in the backend (meaning they are just syntactic sugar)@Coder100 smh
That is how to properly replace while loops with for loops.
Also who really cares about code looking pretty? If it works it workssorry competitive programmer here, and this is somewhat of a joke post.no, that isn't it,
for
loops desugar to@FlaminHotValdez
@Coder100 yes I know, this is somewhat of a joke post, its rly just your opinion.
well i just made one too bruhh @FlaminHotValdez
https://repl.it/talk/learn/How-to-fix-ANY-bug-works-2021/116336 @FlaminHotValdez