Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

c++ loops

Options
  • 28-11-2005 6:24pm
    #1
    Registered Users Posts: 757 ✭✭✭


    hey have to do loops in a question ere. how do you run the "do" loop. is it no cout>> till after the "while" is written or what?


Comments

  • Registered Users Posts: 7,498 ✭✭✭BrokenArrows


    in c++ a do while loop is formatted like this:

    do{
          // Code Here
          // Code Here
    }while(condition here);
    

    All the code inside the brackets is executed once before the while condition is checked.

    Not sure what you mean by
    is it no cout>> till after the "while" is written or what?


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    Not sure what you mean by[...]
    I think he means, does the 'do' block execute once before 'while' is evaluated... or does it ignore the 'do' block until it's had a chance to evaluate 'while'.
    hmm


  • Registered Users Posts: 7,498 ✭✭✭BrokenArrows


    I think he means, does the 'do' block execute once before 'while' is evaluated... or does it ignore the 'do' block until it's had a chance to evaluate 'while'.
    hmm


    If you meant this.

    The code in the do block is executed once without any conditions and then for every subsequent loop it is based on the while condition.


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    The difference between do-while and while is the following...

    while(CONDITION)
    {
    //Code here gets executed, but the condition MUST be true for the loop to start, and must be true for the loop to do another iteration. Here the code may never be executed (Assuming initially the condition is false)
    }

    do
    {
    //Code here gets executed regardless of whether the condition is initially true or false (i.e. the code will ALWAYS get executed at least once), but the code will not loop again unless the condition is true after each iteration.
    }
    while(CONDITION)


  • Registered Users Posts: 757 ✭✭✭Signpost


    this is the code. anyone any idea first y programme wont end when i enter "y" and second y wont it display my strings as facial features on the programme. saved as txt docs cause smaller. - cant upload attachments but email me please @ lanejer@gmail.com and ill send em on. all help appreciated. thanks.
    jer


  • Advertisement
  • Registered Users Posts: 7,498 ✭✭✭BrokenArrows


    Signpost wrote:
    this is the code. anyone any idea first y programme wont end when i enter "y" and second y wont it display my strings as facial features on the programme. saved as txt docs cause smaller. - cant upload attachments but email me please @ lanejer@gmail.com and ill send em on. all help appreciated. thanks.
    jer


    i am trying to get your code to work but it wont compile there are a few syntax errors etc im trying to get it working.

    And another thing talk properly and dont use 'y' instead of 'why'


  • Registered Users Posts: 7,498 ✭✭✭BrokenArrows


    got it compiling eventually but i cannot seem to fix that yes no thing. its weird. ill have a go at it tomorrow but im just angry at it now.


Advertisement