| Start |
|---|
| case Introduces a case label of a switch statement. The operand must be a constant expression and match the switch condition in type. When the switch statement is executed, it will jump to the case label with operand equal to the condition, if any. |
| switch According to the C++ standard, The `switch` statement causes control to be transferred to one of several statements depending on the value of a condition. The keyword The condition must be an expression or a declaration, which has either integer or enumeration type, or a class type with a conversion function to integer or enumeration type. |
| catch The |
| default In a switch statement, introduces a label that will be jumped to if the condition's value is not equal to any of the case labels' values. Defines a default constructor, copy constructor, move constructor, destructor, copy assignment operator, or move assignment operator to have its default behaviour. |
| if Introduces an if statement. The keyword |
| else The first substatement of an if statement may be followed by the keyword |
| goto Jumps to a labelled statement, which must be located in the current function. |
| return Returns control from a function to its caller. If If When |
throw Dynamic exception specifications are deprecated as of C++11. Note that the first two uses of |
| try The keyword |
| Conditional Structures: if, if..else if and else: it used to check whether the given expression returns true or false and acts as such: the condition can be any valid C++ expression that returns something that be checked against truth/falsehood for example: the condition can be anything, a function, a variable, or a comparison for example if we want to check for a multiple expressions we can do it in two ways : using binary operators : using if/ifelse/else: for a simple switch either if or else for multiple choices : however it must be noted that you should use 'switch' instead if your code checks for the same variable's value |
| Jump statements : break, continue, goto, exit. The break instruction: Using break we can leave a loop even if the condition for its end is not fulfilled. It can be used to end an infinite loop, or to force it to end before its natural end The syntax is Example:
we often use in this case if case 1 is satisfied then block 1 is executed , what we really want is only the block1 to be processed but instead once the block1 is processed remaining blocks,block2,block3 and blockdefault are also processed even though only case 1 was satified.To avoid this we use break at the end of each block like : so only one block is processed and the control moves out of the switch loop. break can also be used in other conditional and non conditional loops like example: The continue instruction: The continue instruction causes the program to skip the rest of the loop in the present iteration as if the end of the statement block would have been reached, causing it to jump to the following iteration. The syntax is Example consider the following : which produces the output: i this code whenever the condition The goto instruction: It allows making an absolute jump to another point in the program. You should use this feature carefully since its execution ignores any type of nesting limitation. The destination point is identified by a label, which is then used as an argument for the goto instruction. A label is made of a valid identifier followed by a colon (???? The syntax is Note: Use of goto statement is highly discouraged because it makes difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Example : output : whenever the condition The exit function:
RemarksCheck out the loops topic (opens new window) for the different kind of loops. |
Read Article
https://develop.horje.com/learn/1434/reference