• Advertisement
Sign in to follow this  

Compound statements?

This topic is 3579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What is the function of a compound statement if it is not associated with a conditional? (if(), for(), while() etc.)

Share this post


Link to post
Share on other sites
Advertisement
to... not compile.

With the exception of "for"; an omitted conditional will be replaced with "true".

Share this post


Link to post
Share on other sites
If you mean something like:

{
//stuff
// something that isn't an if, while, etc.
{
// other stuff
}
}

Then the nested compound statement introduces a new scope. You can use it to make sure a temporary value you need is destroyed as soon as it isn't being used. Ex:

Mutex m("mutex name");
{
Lock l(m);
// stuff that needs to be done while the mutex is locked
}
// mutex is unlocked as as the scope is exited

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement