Results 1 to 12 of 12
  1. #1
    yaserifti1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    The finest pussies of Earth
    Posts
    251
    Reputation
    9
    Thanks
    10
    My Mood
    Angelic

    While statements?

    Which one is better to use?

    do {
    statements
    } while (condition)

    or

    while (condition) {
    statements
    }

    or

    for (initialization; condition; increase) statement;
    Key:
    = done
    = not done
    = working on it
    = damn I killed it!

    Accomplishments On MPGH:

    make a mod -

    make a gun to gun mod -

    make a hack -

    learn C++ -

    roast a nub -

  2. #2
    flashlight95's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    12-34 Poopie Street Posts: Over 9000!
    Posts
    128
    Reputation
    10
    Thanks
    15
    Depends on what you're using it for.

  3. #3
    cookie hack's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Location
    Everywhere
    Posts
    150
    Reputation
    10
    Thanks
    11
    My Mood
    Relaxed
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    whatever gets the job done best.






  4. #4
    yaserifti1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    The finest pussies of Earth
    Posts
    251
    Reputation
    9
    Thanks
    10
    My Mood
    Angelic
    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?
    Key:
    = done
    = not done
    = working on it
    = damn I killed it!

    Accomplishments On MPGH:

    make a mod -

    make a gun to gun mod -

    make a hack -

    learn C++ -

    roast a nub -

  5. #5
    flashlight95's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    12-34 Poopie Street Posts: Over 9000!
    Posts
    128
    Reputation
    10
    Thanks
    15
    The one that gets the job done is probably the one that works best.

  6. #6
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,035
    Reputation
    340
    Thanks
    2,784
    My Mood
    Sad
    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
    }

  7. #7
    yaserifti1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    The finest pussies of Earth
    Posts
    251
    Reputation
    9
    Thanks
    10
    My Mood
    Angelic
    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...
    Key:
    = done
    = not done
    = working on it
    = damn I killed it!

    Accomplishments On MPGH:

    make a mod -

    make a gun to gun mod -

    make a hack -

    learn C++ -

    roast a nub -

  8. #8
    Departure's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    818
    Reputation
    125
    Thanks
    1,785
    My Mood
    Doh
    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)

  9. #9
    why06jz's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    299
    Reputation
    14
    Thanks
    54
    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.

  10. #10
    Departure's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    818
    Reputation
    125
    Thanks
    1,785
    My Mood
    Doh
    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.

  11. #11
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    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.
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  12. #12
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,035
    Reputation
    340
    Thanks
    2,784
    My Mood
    Sad
    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.
    =( !