0
752views
Compare the following :

a. Break and continue statements

b. If-else and switch statements.

Subject : Structured Programming Approach

Title : Control Structures

Difficulty : Medium

1 Answer
0
0views

i. break and continue statements

break statement:

The break statement neglects the statement after it in the loop and transfer the control outside the loop.

Operation of break statement in for loop:

for(initialization;condition;inc/dec)

enter image description here

Continue statement:

The continue statement also neglects the statement after it in the loop and transfer the control back to the starting of the loop for next iteration.

Operation of continue statement in for loop:

enter image description here

ii. if-else and switch statements

Sr.no If......else Switch
1. In this we can test only one condition. In this we can test multiple condition.
2. It can have values based on constraints. It can have values based on user choice.
3. In this we cannot have different conditions. In this case we can have only one expression but various value of the same expression.
4. If else statement is used to evaluate a condition to be true or false A switch case statement is used to test for multiple values of the same variable or expression like 1,2,3 etc.
Please log in to add an answer.