Compound statements?

Started by
2 comments, last by Noods 15 years, 11 months ago
What is the function of a compound statement if it is not associated with a conditional? (if(), for(), while() etc.)
Advertisement
to... not compile.

With the exception of "for"; an omitted conditional will be replaced with "true".
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
Thanks!

This topic is closed to new replies.

Advertisement