COMP SCI 200 Study Guide - Midterm Guide: Syntactic Sugar, Unit Testing, Member Variable

111 views37 pages

Document Summary

Set up: while (cond) { loopstatement1; loopstatement2; loopstatementn; i++ = i+=1 = i = i + 1: pre vs post incr/decr operators. Ex) what is the output? int i = 0; System. out. print(++i); increases i first, then prints new value. System. out. print(i++); prints current value of i, then increases. System. out. print(i); prints newest value of i: answer: 112 i = 0 1 2 output: 112. Ex) what is the last number output? int i = 10; while (i != 5) { System. out. print(i + ); i -= 2: answer: infinite loop (i will never equal 5 since i starts at 10 and is decreasing by 2 during each loop) To avoid this situation use: , >= o. For loop for (init; cond; incr) { loopstatement1; loopstatement2; loopstatementn; Ex) what is the output? for(int i = 0, j = 1, k = 3; i < 3; i++, j += 2, k += 3) {