Possible Duplicate:
Why was the switch statement designed to need a break?
I have this:
switch(i)
{
case a:
{
//code
}
case b:
{
//code
}
case c:
{
//code
}
}
If i == a, will the code in b and c be executed or must I put a break; in each one?
Thanks,
Yes, if you only want a single case to execute. Alternatively, other control flow statements can also cause a
switchto be exited, likereturnorthrow.If you were to replace
//codewith, say,std::cout << "case [x]" << std::endl, the answer would be readily apparent.