Follow us on: facebook twitter linkedin

PROGRAMING

Switch vs conditional statement in C

Post by : John Deo
Post date: 2023-11-28 14:34:29

Read time : 2 minute
Total views: 369 times
hero-img

Switch statement:

Instead of writing many if else conditions switch statement could be easily for reduce program execution time. 

 

Syntax for switch statement:

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}

 

In the switch reserve word expression value should be define.

 

If any case value match with switch value. Then execution will be stop for switch statement and program execution will be start to next line. 

 

If else statement:

For example 10 if else statement for similar flow. Once execution start and match found there is less chance stop execution.

Share by:

Keep exploring

Read what excites, achieves and moves us Read what excites, achieves and moves us