Learn
Nice work! Let’s iterate over what you’ve just learned about loops:
while
loops: These are useful to repeat a code block an unknown number of times until some condition is met. For example:
int wishes = 0; while (wishes < 3) { // code that will run wishes++; }
for
loops: These are ideal for when you are incrementing or decrementing with a counter variable. For example:
for (int i = 0; i < 5; i++) { // code that will run }
- For-each loops: These make it simple to do something with each item in a list. For example:
for (String inventoryItem : inventoryItems) { // do something with each inventoryItem }
Instructions
Feel free to play around with loops, arrays, and ArrayLists
in the code editor.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.