answersLogoWhite

0


Best Answer

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

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between 'switch' statement and 'if' statement?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Basic Math

What is difference between basic command and statement?

difference between command and statement


What is the difference gwbasic commands and statements?

difference between command and statement


What is the difference between a declarative statement and an imperative statement?

In a declarative statement, you initialize the object. But in an imperative statement, you use a preexisting statement and use it.


How do you use a switch statement in GML?

Switch Statements are used to generate different outputs of code based on the value of an expression. Switch Statements work as follows:{randomNumber = floor(random(3))+1;switch(randomNumber) {case 1: { } break;case 2: { } break;case 3: { } break;default: { } break;}}This may seem confusing if you are new to GML, so I will give an in-depth explanation. The first line sets the variable randomNumber to a random number between 0 and 2, and adds it by 1 to make it a random number from 1-3. So far the only thing that has gone on in the code is to set a variable to either 1, 2, or 3. This is where the switch statement comes in.switch(randomNumber) {case 1: { } break;case 2: { } break;case 3: { } break;default: { } break;}this is the actual switch statement. You may be wondering what the case statements are for. case statements are always written inside switch statements and do nothing anywhere else. case statements activate when the expression in the switch statement is the same as the value that they are assigned to. Take a look at this switch statement:{rand = floor(random(3));switch(rand) {case 0: {show_message("The Random Value Was 0");} break;case 1: {show_message("The Random Value Was 1");} break;case 2: {show_message("The Random Value Was 2");} break;}} When the values assigned to the case statements are equal to the expression in the switch statement, the case statement will run the code contained in it's brackets. break statements order the switch statement to abort. The reason that you need break statements inside a switch statement is because it keeps the other cases from activating as well. (When one case statement activates, the others do as well.)A final briefing on switch statements is that they are not limited to variables. Take a look at this switch statement.{switch(obj_block.x > x) {case true: {show_message("The Block Is Ahead Of You.");} break;case false: {show_message("You Are Ahead Of The Block.");} break;}} This switch statement returns a true or false value, and the case statements operate accordingly.


What is the difference between if-else and else-if?

if-else implies a first statement, while else-if implies that we would know what else is but we don't because else is defined by if.

Related questions

What is difference between basic command and statement?

difference between command and statement


What is the difference between a descriptive and an explanatory statement?

What is the difference between a descriptive and an explanatory statement?


What is the difference between bar scale and statement scale?

What is the difference between a bar scale and a statement scale


Difference between TPN switch and TP and N switch?

no difference whatsoever


What are the difference between command and statement?

i am starving


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 gwbasic commands and statements?

difference between command and statement


What is the difference between an objective statement and nonobjective statement?

The lack of observable evidence


What is the difference between an objective statement and a nonobjective statement?

The lack of observable evidence


What is the difference between an objective statement and the nonobjective statement?

The lack of observable evidence


Difference between scope statement and project charter?

The difference between a scope statement and a project charter is that a project charter acknowledges the projects existence and the scope statement defines the project objectives.


Difference between tandem switch and long distance switch?

go to www.howstuffworks.com