In the past I have always used break on a switch statement. Each case being handled separately and a default being left at the end for exceptions.
Today I came across a different scenario, and in this example by leaving out the break; it will save me lines of duplicate code. At least I think it will.
Code: Select all
switch ($action){
case 0: #new file
//do something
break;
case 1: #edit file
//do something
break;
case 2: #create a default file
//set up variables as if a new file had been created but using default values
case 3: #save the file
//run save routines, that are needed to create any file.
break;
}I was wondering if this is a good/bad coding practice. A colleague thinks it could be shaky if someone else edits the code and put something between case 2 and case 3, but I think with suitable commenting a decent programmer would understand whats been done.
What are your thoughts? Comment?