CPS 196 Study Guide - Quiz Guide: For Loop, Scanf Format String, While Loop

130 views3 pages

Document Summary

If-else: allows branching (decision making) based on value or state of variables. Blocks: allows multiple statements to be used in place of a single statement. Nested if: allows multiple branches by cascading comparisons. Branch taken is first comparison which results in true. Switch: multi-way decision testing expression against integer values. The break statements do not have to be included at the end of each case. If the breaks are omitted, program flow will continue into the next case. Num1, num2, total; printf( enter two numbers: ); scanf( %d %d , &num1,&num2); printf( select hoice:\n ); printf( (1) addition\n ); printf( (2) subtraction\n ); scanf( %d , &menu); switch (menu) {case 1: total= num1 + num2; break; case 2: total= num1 + num2; break; printf( total: %d\n , total); While loop: repeats an action until an associated test returns false. Do while: test occurs after body of loop.