Friday, September 26, 2008

Switch in c++

Today I start use switch to do something . But I missed a important thing , that's the term 'break' in Switch just make program get out "switch". I have though "break " just work for loop ,like "for" and "while". Now I know it also work for "switch".

switch(flag)
{
case 1:
//here break just make program get out switch ,dont check case 2 and 3.
break;
case 2:
//do sth, if you dont add break , the program will go to case 3 to check;
case 3:
break;

}

No comments: