Sign in to follow this  
Kest

Looking for something in a loop

Recommended Posts

This is a trivial question, driven by curiosity alone. When you're looping to check for the existence of something, how do you prefer to "remember" that you found one, once you're outside of the loop? For example, if I wanted to make sure a suit contained the right shape to fit a certain person when that person is looking through them, I don't need to keep any records, other than that the suit supports that person's shape. This is how I could do it:
BOOL found_shape = false;
for(int m=0; m<Shapes.GetCount(); m++)
{
	if( Shapes[m] == Person->GetShape() )
	{
		found_shape = true;
		break;
	}
}

Here's another way I could have done it:
int m;
for(m=0; m<Shapes.GetCount(); m++)
	if( Shapes[m] == Person->GetShape() )
		break;
BOOL found_shape = ( m < Shapes.GetCount() );


Is that basically how everyone does it? Or are there any other ideas?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this