







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Error in HW2, problem 4b Free points for everyone May want to start HW2 early (Covers week 3, Ch 1.2-1.4) (Already 10+ days old)
Often we want to do a (similar) command more than once Computer programmers call this code a loop Loops are quite powerful and are very commonly used
The boolean expression is tested when first entering the while loop And! When the end of the loop code is reached (the } to close the loop)
3 parts to any (good) loop:
Q: Why would I ever want a do-while loop? A: When the first time the variable is set is inside the loop. You can initialize the variable correctly and use a normal while loop, but this makes the logic harder (Kitty code) (See: Password.java)
A for loop is a compacted version of the while loop (the 3 important parts are together) for loops are used normally when iterating over a sequence of numbers (i.e. 1, 2, 3, 4) (See: ForLoop.java) Initialization boolean expression Update
Very often used for String parsing (See: StringToNumber.java) If time... (See: StringToNumberSneaky.java)