Decision Control Instructions There are 3 major decision control instructions. if if-else switch the condition operators [ ternary operators] Syntax of If if(expression) execute the statement; // ; statement terminator If the expression is true, execute the immediate next statement. If the expression is false skip the statement. How do we evaluate if the expression is true or false. with the help of relational operators, we will evaluate that the expression is true or false. we will determine whether two statements are equal, unequal or one is greater than other. In C language, all arithmetic expressions are valid. They are considered as true or non-zero values. In C language, every test expression is evaluated as zero or non-zero value. Zero is equal to false and non-zero is equal to True. Scope of if By default, scope of if is the immediate next statement after it. If we want mor...
Switch is the case control statement that allows us to make a decision from the number of choices. It is also called switch case default. These three keywords go together to make up the control statement. Syntax of switch case default The integer expression following the switch keyword is any c expression that yields the integer value. [Characters also since they do have ASCII value interpretations] It could be an integer constant like 1, 2 or 3 or any expression that evaluates to an integer. The keyword case followed by an integer constant or character constant. Each constant in each case must be different from all other cases. The integer expression following the keyword switch is evaluated and yields an integer value. The integer value must be matched across the cases. When a match is found-The program executes following 1. The statement following that case. 2. All subsequent cases. 3. Default case as well. Keyword break stops executin...
Comments
Post a Comment