Switch-Case control statements

In addition to two-way selection, most programming languages provide another selection concept known as multi-way selection. Multi-way selection chooses among several alternatives. C++ has two different ways to implement multi-way selection. The switch statement and else-if construct If for suppose we have more than one valid choices to choose from then we can use switch statement in place of if statements. Syntax: As you can see in the above scheme the case and default have a “break;” statement at the end of block. This expression will cause the program to…

Read More

Unconditional Control Statements

Statements that transfers control from on part of the program to another part unconditionally Different unconditional statements are goto break continue 1. goto Statement The goto statement is used for unconditional branching or transfer of the program execution to the labeled statement. The goto statement is strongly discouraged as it makes it difficult to follow the program logic, this way inducing to errors. In some (mostly rare) cases the goto statement allows to write uncluttered code, for example, when handling multiple exit points leading to the cleanup code at a…

Read More