I'm just sitting here mindlessly playing League of Legends while pondering the do while loop. While I sit here pondering as my hero gets blown to pieces, I wonder, what is an actual advantage of a do while loop. I can't really seem to find an advantage in the knowledge that I hold. So as I continue playing League of Legends I will continue pondering on this while asking someone the question: What are good advantages of a do while loop? I'm pretty clueless.
with a do loop it does the shit once before it validates to see if it should keep doing it or skip it all together.
im sure there is a use but i cant be bothered thinking of a situation :P
Do While will execute the command first before checking for condition. Advantage is when you know you will have a constant command in the 1st iteration.
While will execute the command after checking for condition.
U mean vs For loop?
While loop could save you 75% to 88% memory bytes vs For loop, esp. in situation where you use boolean datatype for the while loop condition. Remember boolean is a very inexpensive datatype, only contains bits 0 and 1 (1 byte). For loop typically uses integer for index cursors, with increment and decrement, more expensive than boolean (int is 4 bytes, longint is 8 bytes).
Think of it this way. For loop is better when you know how many iterations you're gonna go through. While loop is better is you are unsure how many iteration to go.
1 byte vs 4 or 8 bytes might sound small but in a situation where u use many vars, it could make big difference.
That's all I can think of. I might be wrong, correct me if i am, my memory is kinda rotten lolz...
I was thinking a do while vs a while or for loop, I didn't explain very well because I was in a game. I know what the do while loop and all that does. I was just thinking advantages it has against other loops. I created the topic because I thought it might be good for conversation since there are many ways a do while loop could be put against others. :)
With a while loop you can do things like...
while(true){revivemichaeljackson}
or you can have...
do{revivemichaeljacksonwhile(true)}
The brain scratcher for me is, wouldn't it be better to test if it is indeed true before executing code so then the CPU does not have to work as much?
Edit: Code is pretty unclear, its just an example.
I'm just sitting here mindlessly playing League of Legends while pondering the do while loop. While I sit here pondering as my hero gets blown to pieces, I wonder, what is an actual advantage of a do while loop. I can't really seem to find an advantage in the knowledge that I hold. So as I continue playing League of Legends I will continue pondering on this while asking someone the question: What are good advantages of a do while loop? I'm pretty clueless.
@iSaintx: Go
C++, or in general?
i used it frequently.
do something while condition = true
maybe gain health while in radius of a building
hey we have an aura!
ofcourse this could be done easier and more efficiently in data. but thats irrelevant.
with a do loop it does the shit once before it validates to see if it should keep doing it or skip it all together.
im sure there is a use but i cant be bothered thinking of a situation :P
@iSaintx: Go
What do you mean? Do While vs While?
Do While will execute the command first before checking for condition. Advantage is when you know you will have a constant command in the 1st iteration. While will execute the command after checking for condition.
U mean vs For loop? While loop could save you 75% to 88% memory bytes vs For loop, esp. in situation where you use boolean datatype for the while loop condition. Remember boolean is a very inexpensive datatype, only contains bits 0 and 1 (1 byte). For loop typically uses integer for index cursors, with increment and decrement, more expensive than boolean (int is 4 bytes, longint is 8 bytes).
Think of it this way. For loop is better when you know how many iterations you're gonna go through. While loop is better is you are unsure how many iteration to go.
1 byte vs 4 or 8 bytes might sound small but in a situation where u use many vars, it could make big difference.
That's all I can think of. I might be wrong, correct me if i am, my memory is kinda rotten lolz...
@deathtorn: Go
In general, sorry. I only know C + + and I know how to print text in Java. o.O
@Maknyuzz: Go
I was thinking a do while vs a while or for loop, I didn't explain very well because I was in a game. I know what the do while loop and all that does. I was just thinking advantages it has against other loops. I created the topic because I thought it might be good for conversation since there are many ways a do while loop could be put against others. :)
With a while loop you can do things like...
or you can have...
The brain scratcher for me is, wouldn't it be better to test if it is indeed true before executing code so then the CPU does not have to work as much?
Edit: Code is pretty unclear, its just an example.
@iSaintx: Go
You're thinking about it wrong.
Think about it this way, what if everyone starts with 1 free coin, and more bonus coins for every extra "point" they have.
With a while loop, you'd have to do:
Wait, Rodrigo made a smurf account and is now applying his subtle advertising techniques to support League of Legends?
@MotiveMe: Go
Hah, that is embarrassing. :[ That clears things up a bit. :)
@Mozared: Go
I lol'd. If you want proof it's not Rodrigo, DL League of Legends and watch me suck...I usually end up with 3 assists and 9 deaths. o.O