Do While loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tippy

    Do While loop

    I tried to get cout to view after do while loop but I can't

    do{

    }while (number != Rand);

    cout<< "Got it";
    return 0;

    the word "Got it" never show.
    Please help.
    Thanks.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Put a cout inside your loop and tell me what you see.

    Comment

    • Oralloy
      Recognized Expert Contributor
      • Jun 2010
      • 988

      #3
      It seems to me that there is no action inside the block of your do loop, which changes the state of the computation.

      Therefore, the termination condition will never change. Ergo, the loop will execute exactly once, or it will never exit, depending on the values of the variables in the exit condition.

      Good luck. Weaknessforcats is _really_ _really_ good. Listen to what she says, and you'll learn a lot.

      Comment

      • Jose Diaz
        New Member
        • Nov 2010
        • 6

        #4
        First of all
        do{

        }while (number != Rand);

        its going to loop forever (INFINITE LOOP).

        The reason cout<< "Got it"; Never showed was because the do-while loop never terminated thus not allowing cout to print message to screen. Put cout<< "Got it"; inside do-while loop. Remember that the message will print forever so make sure you terminate it. In order to terminate it you need to make number equal Rand. (*HINT HINT!) =)

        Comment

        Working...