Topic: switch statement

Kindly could any one tell me the difference between

break;
                default:
                    break;
            }
 
            return;

 

AND

break;

   
I noticed some indicators '' Calculation Part'' ends with the first and some end with the second , despite the action is the same which is enter or exit at a specific level

Re: switch statement

int caseSwitch = 2;
switch (caseSwitch)
{
    case 1:
        Console.WriteLine("Case 1");
        break;
    case 2:
        Console.WriteLine("Case 2");
        break;
    default:
        Console.WriteLine("Default case");
        break;
}

the switch is like multiple "if" statements. if the case value matches the switch condition the code for that case is executed, if there is a break inside that "case", the switch statement is exited and the remaining case checks are not performed. the default will execute if the code reaches that point in the "switch" without hitting a break before that.

the return; after the } exits the current function or procedure.

in the current example if there was no "break;" in case 2 the output would be:

Case 2
Default Case

with the break it would be:

Case 2