# Loops Coding Practice (2.7-2.12)

Each coding exercise has its own folder. Open its `.java` file and press **Run** to try it. **Run Tests** checks every graded exercise in this lesson at once.

## Exercise 1

Rewrite the code so that it uses a `for` loop instead of a `while` loop to print out all the integers from 5 to 1 (inclusive).

> Open the `01-looppractice1` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 2

Rewrite the code to use a `while` loop instead of a `for` loop to print out the numbers from 1 to 10 (inclusive).

> Open the `02-looppractice2` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 3

Rewrite the code so that it uses a `for` loop instead of a `while` loop to print out all the integers from 5 to 15 (inclusive).

> Open the `03-looppractice3` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 4

Rewrite the code to use a `while` loop instead of a `for` loop to print out the numbers from 10 to 100 by 10’s (inclusive).

> Open the `04-looppractice4` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 5

The code should print the values from 1 to 10 (inclusive) but has errors. Fix the errors so that the code works as intended. If the code is in an infinite loop you can press Ctrl+C in the terminal to stop the loop.

> Open the `05-looppractice5` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 6

The code should print the values from 10 to 5, but it has errors. Fix the errors so that the code works as intended.

> Open the `06-looppractice6` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (1 test).

## Exercise 7

The code should print the values from 10 to 1, but it has errors. Fix the errors so that the code works as intended.

> Open the `07-looppractice7` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (1 test).

## Exercise 8

Finish the code to print a countdown from 100 to 0 by 10’s using a for or while loop.

> Open the `08-looppractice8` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 9

Finish the code to print the value of `x` and `" is even"` if `x` is even and `" is odd"` if it is odd for all values from 10 to 1.

> Open the `09-looppractice9` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 10

Finish the code to print the values for `10 * x` where `x` changes from 0 to 10 using a loop.

> Open the `10-looppractice10` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 11

Finish the code so that it prints a string message minus the last character each time through the loop until there are no more characters in message.

> Open the `11-looppractice11` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 12

Finish the code to loop printing the message each time through the loop and remove an `x` from the message until all the `x`’s are gone.

> Open the `12-looppractice12` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 13

Write a loop below to print the number of `x`’s in the string message. Use the `substring` method.

> Open the `13-looppractice13` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 14

Write the code to print a rectangle of stars (`*`) with 5 rows of stars and 3 stars per row. Hint: use nested for loops.

> Open the `14-looppractice14` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 15

Write the code to print a rectangle of stars (`*`) with 3 rows of stars and 5 stars per row.

> Open the `15-looppractice15` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 16

Write the code to print 55555, 4444, 333, 22, 1 with each on a different line.

> Open the `16-looppractice16` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).
