Loop Exercises
For Loops
- Display the message “Hello World!” 25 times
- Change the program so that the user can decide how many times to display “Hello World” on the screen.
- Display the number of the repetition on the screen as well (eg. 1. Hello World!, 2. Hello World!, etc.)
- Ask the user which times table they wish to see, then display it in the following format:
1 * 7 = 7
2 * 7 = 14
.
.
12 * 7 = 84 - Ask the user how many stars they want to see in one row. Display the row of stars
- Expand your solution and ask the user how many rows of stars they want to see. Display the rectangle of stars as specified by the user. Hint – you will need to nest one For loop inside another!
While Loops
- Ask the user to enter a whole number greater than 99. If the user enters a number less than 100, display an error message and ask them again. Repeat this process until the user enters a valid number.
- Expand your solution to only accept numbers between 100 and 200
Repeat Loops
- Add up a series of whole numbers entered by the user, until the user enters zero.
- Expand your solution to display the average value of the numbers entered. Hint: do not count the final zero as a value to be averaged.
Categories: General