While statements?

Posts 112 of 12 · Page 1 of 1
While statements?
Which one is better to use?

do {
statements
} while (condition)

or

while (condition) {
statements
}

or

for (initialization; condition; increase) statement;
Depends on what you're using it for.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
whatever gets the job done best.
Don't post just to get your count up, I know whichever one gets the job done, but I'm asking which one gets it done better?
The one that gets the job done is probably the one that works best.
Neither, it depends on how you want it.

do {
// will execute AT LEAST ONCE, regardless if the condition is met or not.
} while (condition)

or

while (condition) {
// will execute ONLY if the condition is met
}
Quote Originally Posted by freedompeace View Post
Neither, it depends on how you want it.

do {
// will execute AT LEAST ONCE, regardless if the condition is met or not.
} while (condition)

or

while (condition) {
// will execute ONLY if the condition is met
}
Ah, thanks for a real answer unlike the idiot who keeps posting the same thing, the guy with a flashlight for a profile pic...
There is a speed difference between "for" statement and "while" statements, it depends on how many loops gets processed(at least this is the case in delphi)
He's not an idiot. He assumed you knew basic C++ ur the idiot for not knowing it and asking a question that has no right answer. What you should have asked is "what does this do, cuz idk?"

Also there's no speed penalty. All loops get transformed into do-while loops when assembled. at least for VS & Delphi. there's 1 extra jump because the value is incremented after the boolean evaluation, so it skips this the first run through. that's it.
No offence but your wrong about the speed penalty for Delphi, There is a difference and they do not both compile into the same op code. VS I can't say because I have never actually tested it like I have with Delphi, I have even timed them both and written a small delphi application to back up my claims.
Ahh BLA BLA BLA!!!!

ONE : i dont think he is using Delphi (thanks for the info on it.. Need to learn that language for school "pascal")
TWO: The difference between the FOR and the WHILEs is this
For does Counting for you, while you have to do your own counting... Better.
Quote Originally Posted by yaserifti1 View Post
Ah, thanks for a real answer unlike the idiot who keeps posting the same thing, the guy with a flashlight for a profile pic...
Oh, I forgot about the for loop: for will execute a statement, kind of like the while clause, but will allow you to initials a variable just for the counting, and automatically increment it.

So you would use a for loop for you want to execute something a certain amount of times, or you want to iterate through an array (where your initialized variable would be your current item). A while loop would execute code while an already declared variable is a certain value (while executingDownlad, block input to form). Also applies to do, but where you want to do something once (whole Downloading, std::cout<<"Downloading...")


Quote Originally Posted by topblast View Post
Ahh BLA BLA BLA!!!!

ONE : i dont think he is using Delphi (thanks for the info on it.. Need to learn that language for school "pascal")
TWO: The difference between the FOR and the WHILEs is this
For does Counting for you, while you have to do your own counting... Better.
=( !
Posts 112 of 12 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?