COMP 202 Lecture Notes - Lecture 13: Boolean Expression
jc123 and 40170 others unlocked
100
COMP 202 Full Course Notes
Verified Note
100 documents
Document Summary
Tracing loop code int i = 1; while(i<50){ A for loop is a while loop with a built-in" counter. The two types of loops are equivalent, and you should use whichever seems more appropriate. 64 is larger than 50, so loop ends. Then, the condition is checked again, and if true, the loop body is executed. You can leave out any or all of the above three statements/expressions. (you don"t have to put anything there). You will always have two semi-colons inside the parentheses. They never leave out the boolean expression (but you can). if you need to take away most of the statements, you should probably be using a while loop. For loops vs while loops int i=1 while(i 10) { Check if it is divisible by 2. Otherwise: check if it is divisible by 3. If it is, then it is not prime. Continue until the square root of that number!