filmov
tv
Switch statement syntax in CPP using Dev-C++

Показать описание
In today video session we will discuss another implementation of selection structure in C++ using switch statement.Switch statement in C and C++ are implemented in the similar way. Switch statement is good alternative of if else statement. Multiple if else statement become more complicated and complex while checking multiple conditions. So in that situation switch statement is good choice.
Here we use Dev-C++ IDE for writing C++ program.
Switch statement is also used where we have to match some atomic value from the multiple cases. In switch statement we use arithmetic expression in place of relational expression. This arithmetic expression returns any single value.This single value then match from the provided case statements in the body of switch statement. Each case statement followed by colon. Before every new case statement break statement is used. Whenever any case statement become true then the remaining case statements are not checked.
An important point regarding case statement is also discussed in this session is that when one case statement will true and we have not used break statement after this case statement then all remaining statements will be executed. The compiler will not match the remaining case statements, it just execute all the next coming statements. So that it is mandatory to use break statement after each case statement.
After writing down the all case statements the default block is also written in switch statement. This default statement is also followed by colon. This default block will execute when none of the provided case will true.
Here we use Dev-C++ IDE for writing C++ program.
Switch statement is also used where we have to match some atomic value from the multiple cases. In switch statement we use arithmetic expression in place of relational expression. This arithmetic expression returns any single value.This single value then match from the provided case statements in the body of switch statement. Each case statement followed by colon. Before every new case statement break statement is used. Whenever any case statement become true then the remaining case statements are not checked.
An important point regarding case statement is also discussed in this session is that when one case statement will true and we have not used break statement after this case statement then all remaining statements will be executed. The compiler will not match the remaining case statements, it just execute all the next coming statements. So that it is mandatory to use break statement after each case statement.
After writing down the all case statements the default block is also written in switch statement. This default statement is also followed by colon. This default block will execute when none of the provided case will true.
Комментарии