|
-
Oct 5th, 2000, 02:25 PM
#1
Thread Starter
Member
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
-
Oct 5th, 2000, 02:50 PM
#2
Addicted Member
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
-
Oct 5th, 2000, 03:44 PM
#3
Frenzied Member
Use the break keyword;
Example:
Code:
for( ; ; ) // No termination condition.
{
if( List->AtEnd() )
break;
List->Next();
}
cout << "Control transfers to here.\n";
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|