Do While or While

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kid Programmer
    New Member
    • Mar 2008
    • 176

    Do While or While

    Is there a difference between a do while loop and a while loop or are they different ways of accomplishing the same thing.
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    They are almost identical. However, in a do-while loop, the code is executed once before the loop termination condition is checked. In a while loop, the condition is checked first.

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      The next question is often: which should I use to do X? My rule of thumb is try the while loop first. Situations where the do-while loop is a better choice are not as common.

      Comment

      • akksaravanan
        New Member
        • Apr 2008
        • 1

        #4
        While --> Each time it checks the condition before executing the block of code.
        do..While -----> Executes the block of code and checks the condition.
        Syntax
        while(expression)
        {
        //Block of code
        }
        ............... ....
        do
        {
        //Block of code
        }
        while(expression)

        Comment

        • Kid Programmer
          New Member
          • Mar 2008
          • 176

          #5
          Okay thanks guys. I understand.

          Comment

          Working...