answersLogoWhite

0


Best Answer

switch is a loop which is used for checking various conditions and print corresponding matter.

switch(a)//where a is that whose condition you have to check.

#include

main()

{

char a;

printf("enter a char.");

scanf("%c",&a);

switch(a)

{

case 'a':printf("vowel");break;

case 'e':printf("vowel");break;

case 'i':printf("vowel");break;

case 'o':printf("vowel");break;

case 'u':printf("vowel");break;

default:printf("consonent");

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

SWITCH is a shortcut to avoid a long series of nested IF statements.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When should a switch statement be used?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can a continue statement be used in a switch statement?

If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).


What does default mean in switch statement?

Default clause in switch statement used to indicate that the desired option is not available with the switch case statement. it is similar to else statement of if statement which is used when the condition does not satisfy.


What are control structures used in javascript?

The control structures used in java script are if-statement, for-loop, for-in loop, while loop,do-while loop, switch-statement, with-statement. try-catch-finally statements.


The break statement is required in the default case of a switch selection structure?

Ends the case statement. Without it, any code after where the break; is supposed to be will get executed as well until it does encounter a break; or the end of the switch.Code Example:char cTest = 'a';switch(cTest) {case 'a':/* Code here gets executed. */case 'b': //* Code here gets executed. */case 'c':/* Code here gets executed. */break;case 'd':/* Code here won't be executed. */default:/* Code here won't be executed. */}


What are the disadvantages of switch statement in C-language?

In some languages and programming environments, a case or switch statement is considered easier to read and maintain than an equivalent series of if-else statements, because it is more concise. However, when implemented with fall-through, switch statements are a frequent source of bugs among programmers new to the switch statement.

Related questions

Can a continue statement be used in a switch statement?

If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).


How 'if' statement is different from a 'switch' statement in C language?

The if statement is used to select among two alternatives. It uses a boolean expression todecide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternativeshould be executed.


What does default mean in switch statement?

Default clause in switch statement used to indicate that the desired option is not available with the switch case statement. it is similar to else statement of if statement which is used when the condition does not satisfy.


What is the use of switch statement in java?

In java, a switch statement is used to simplify a long list of 'if' statements. A switch statement takes the form of:switch (variableName){case condition1; command1;case condition2; command2;...}


What is the difference between If-else and Switch-case in Java?

The if statement is used to select among two alternatives. It uses a boolean expression todecide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternativeshould be executed.


What is the difference between 'switch' statement and 'if' statement?

we can use switch statement in multiple time but in if statement we can not use multiple time


What is the deffernce of the switch statement and the if statement in c plus plus?

If statement is single selection statement,whereas the switch statement is multiple selective.


What is break in c?

The break statement is used to exit a loop or switch-case.


What are control structures used in javascript?

The control structures used in java script are if-statement, for-loop, for-in loop, while loop,do-while loop, switch-statement, with-statement. try-catch-finally statements.


The break statement is required in the default case of a switch selection structure?

Ends the case statement. Without it, any code after where the break; is supposed to be will get executed as well until it does encounter a break; or the end of the switch.Code Example:char cTest = 'a';switch(cTest) {case 'a':/* Code here gets executed. */case 'b': //* Code here gets executed. */case 'c':/* Code here gets executed. */break;case 'd':/* Code here won't be executed. */default:/* Code here won't be executed. */}


What is case in java?

Case is used to label each branch in the switch statement in Java Program


How if else if statement is differ from switch in general in java?

An else statement is comparing to items, while a switch statement is used to compare multiple items. So if you need multiple results from one statement use a switch but for booleans or very specific functions use a if else statement. Else If ex. if(a=6){System.out.println("It is six");} else(){System.out.println("It is not six");} Switch ex. switch(a){ case 1: System.out.println("it is one"); break; case 2: System.out.println("it is two"); break; default: System.out.println("it is not one or two"); break; } Basically a switch is a good way to check against a lot of possibilities.