







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to loops in programming, explaining the concepts of while, do-while, and for loops. It covers their usage, advantages, and differences. Students may find this useful for understanding the basics of looping structures in java programming.
Typology: Slides
1 / 13
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)