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...
Loops If something is worth doing, it's worth doing more than once. The versatility of computer lies in its ability to perform a set of instructions repeatedly. This involves repeating some portion of the program either a specific number of times or until a condition is being satisfied. This is done by loop control instructions. There are three methods by which we can repeat some portion of the program. while do while for Syntax of while loop initialize loop counter; while (test condition) { execute statement; increment counter; } @program- Flow chart Loop Counter / Index variable - Count variable sometimes called index variable or loop counter. in above program, variable count is loop counter or index variable. It is not necessary that the loop counter should always be an integer value. It can be real number as well. Instead of increment the loop counter we can decrement it as well. Other conditions which can be tested in while loops are: while (i<=10) while (i>=10 &...
Comments
Post a Comment