Results 1 to 3 of 3

Thread: while loops . . .

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 1999
    Location
    Richmond, Virginia
    Posts
    41
    Hey -

    I had a simple question concerning while loops. I need to be able to have code inside a loop exit the loop when a certain condition is met. An example would be the VB code, "exit while". Is there a C++ equivilent? Thanks for your help . . .

    TheLeeMan

  2. #2
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231

    Talking

    It's usally advise to generate the exit condition rather than trying to force your way out of the loop, for example.

    Code:
    while (exit != True)
    {
    ...
    exit = True;
    ...
    }
    or

    Code:
    do
    {
    ...
    exit = true;
    ...
    } while(exit != True)
    Depending on how soon you want to exit, or test for a condition, you can use either a Pre-Test Loop, or a Post-Test loop.

    but I think you can use

    Code:
    break;
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Use the break keyword;
    Example:
    Code:
    for( ; ; )    // No termination condition.
    {
        if( List->AtEnd() )
            break;
    
        List->Next();
    }
    
    cout << "Control transfers to here.\n";
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width