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...
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