Switch case and Continue statement

  • Syntax:
           switch (Expression/Variable)
           {
                case label : statements;
                             break;
               
                case label : statements;
                             breaks;
  
                      ................
                default: statement;
           }
  • Used in menu driven Programs.
  • If we don’t put a break in the case, Complier doesn’t generate error same as default.
  • The break statement is useful for coming out from switch-case.
  • We can write default anywhere in the program but we have to write “break” after it.

Example:

main()
{
     int num;
     printf("Enter the number : ");
     scanf("%d",&num);

     switch(num)
     {
           case 1: printf("1 \n");
                   break;
           case 2: printf("1 \n");
                   break;
           case 3: printf("1 \n");
                   break;
           default:printf("default ... \n");
     }
     printf("Thanks ... \n");
}
  • In one switch case, we cannot write two or more default case otherwise it gives an error.
  • We can write in nested switch case.

Return statement:

  • We can use return statement also at last of the program or anywhere in the program to return any specific value of the variable.
  • There are two types of Return statements:
  • 1. Control return and
  • 2. Value return.
  • Useful in coming out of function loop.

 

Continue Statements:

  • It should be within the loop.
  • For a break, it should be within the loop or switch – case.

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: