# Day 4 Activities
In your `gemcamp_ruby_basic` repository, please create a new folder named `iteration_practice` and solve the following problems. Ensure that your commits are meaningful and clearly describe the following problems.
1. Write a Ruby program that prints "Hello, World!" 5 times using the times method.
1. Use the times method to print the numbers from 0 to 9.
1. Write a Ruby program that prints "I love Ruby!" 7 times using the times method.
1. Create a program that prints the square of numbers from 1 to 10 using the times method.
1. Ask the user for a number and use the times method to print "This is iteration number X" for each iteration, where X is the current iteration number.
1. Write a Ruby program that prints the sum of numbers from 1 to 100 using the times method.
1. Create a program that asks the user for two numbers: how many times to iterate and a word to print. Use the times method to print the word that many times, with each word on a new line.
1. Use the times method to reverse an array of strings. Print each string in reverse order of its original position.
1. Write a Ruby program that asks the user for a number and prints a right-angled triangle of asterisks (*) with the given number of rows using the times method.
```ruby
# *
# **
# ***
# ****
# *****
```
3. Create a program that asks the user for a number and then uses the times method to calculate and print the factorial of that number.
4. Write a Ruby program that prints a series of random numbers between 1 and 100, repeating 10 times, using the times method and rand.
5. Ask the user for a number and print a pyramid pattern of numbers using the times method. For example, for input 5:
```ruby
# 1
# 22
# 333
# 4444
# 55555
```
1. Use the times method to simulate rolling two dice 10 times. After each roll, print both numbers and whether their sum is odd or even.
1. Create a Ruby program that generates a random string of 8 characters, where each character is randomly chosen from a set of lowercase letters a to z (Array), using the times method.
1. Create an array of colors and use the each method to print each color.
```ruby
["red", "blue", "green"]
```
1. Create an array of numbers and use the each method to print each number.
```ruby
[1, 2, 3, 4, 5]
```
3. Create an array of numbers and use the each method to add 2 to each number and print the result.
```ruby
[1, 2, 3, 4, 5]
```
5. Create an array of words and use the each method to print the length of each word.
```ruby
["apple", "banana", "grape"]
```
7. Create a hash with three key-value pairs (e.g., ) and use the each method to print each key and its corresponding value.
```ruby
{a: 1, b: 2, c: 3}
```
9. Create an array of numbers ([2, 4, 6]) and use the each method to print each number doubled.
```ruby
[2, 4, 6]
```
11. Create an array of names and use the each method to capitalize each name and print it.
```ruby
["john", "jane", "doe"]
```
13. Create an array of numbers and use the each method to calculate the sum of all elements in the array.
14. Create an array of numbers and use the each method to print only the even numbers.
15. Create two arrays of equal length and use the each method to multiply corresponding elements from each array and print the results.
16. Create a nested array and use the each method to print each sub-array and its elements.
```ruby
[[1, 2], [3, 4], [5, 6]]
```
18. Create an array of strings and use the each method to reverse each string and print it.
19. Create a string and use the each method on the characters of the string to count the occurrences of each letter, storing the results in a hash.
20. Create two arrays, one with keys and one with values, and use the each method to combine them into a hash.
21. Create an array of words and use the each method to check if each word is a palindrome (a word that reads the same backward as forward).
1. Use a for loop to print numbers from 1 to 10.
1. Use a for loop to calculate and print the sum of all numbers from 1 to 100.
1. Create an array of strings and use a for loop to print each string.
```ruby
["apple", "banana", "cherry"]
```
1. Use a for loop to print the multiplication table of 5.
1. Use a for loop to print only the even numbers between 1 and 20.
1. Create an array of words and use a for loop to print each word in reverse.
1. Create a hash with three key-value pairs (e.g., ) and use a for loop to print each key and value.
```ruby
{name: "Alice", age: 25, city: "New York"}
```
1. Ask the user for a number, and use a for loop to print a right-angled triangle with that number of rows made of stars (*).
1. Create an array of numbers and use a for loop to calculate the sum of all even numbers in the array.
1. Ask the user for a string and use a for loop to count how many vowels (a, e, i, o, u) are in the string.
1. Create an array of numbers and use a for loop to find and print both the maximum and minimum numbers in the array.
1. Ask the user for a sentence, split it into words, and use a for loop to print each word in reverse.
1. Use a for loop to create the following number pattern for a given number of rows
```ruby
1
22
333
4444
55555
```
Use a for loop to print numbers from 1 to 10.
Use a for loop to calculate and print the sum of all numbers from 1 to 100.
Create an array of strings and use a for loop to print each string.
```ruby
["apple", "banana", "cherry"]
```
Use a for loop to print the multiplication table of 5.
Use a for loop to print only the even numbers between 1 and 20.
Create an array of words and use a for loop to print each word in reverse.
Create a hash with three key-value pairs (e.g., ) and use a for loop to print each key and value.
```ruby
{name: "Alice", age: 25, city: "New York"}
```
Ask the user for a number, and use a for loop to print a right-angled triangle with that number of rows made of stars (*).
Create an array of numbers and use a for loop to calculate the sum of all even numbers in the array.
Ask the user for a string and use a for loop to count how many vowels (a, e, i, o, u) are in the string.
Create an array of numbers and use a for loop to find and print both the maximum and minimum numbers in the array.
Ask the user for a sentence, split it into words, and use a for loop to print each word in reverse.
Use a for loop to create the following number pattern for a given number of rows
```ruby
1
22
333
4444
55555
```
### solve the following using while
1. Write a program that counts down from 10 to 1 and prints each number.
1. Write a program that asks the user for numbers and adds them until the user enters 0. Display the total sum.
1. Write a program that asks the user to enter a password. Keep asking until the correct password ("secret") is entered.
1. Create a program that prints the multiplication table for a number, but stops when the product exceeds 50.
1. Write a program where the computer picks a random number between 1 and 100, and the user has to guess it. Keep asking until they guess correctly.
1. Write a program that prints all even numbers from 1 to 20 using a while loop.
1. Write a program that repeatedly asks the user for input and prints it back to them until they type "exit".
1. Write a program that goes through an array and creates a new array containing only even numbers using a while loop.
1. Write a program that counts how many odd numbers are in an array using a while loop and a conditional statement.
1. Write a program that removes all elements greater than 10 from an array using a while loop.
1. Write a program that finds the index of the first occurrence of a number in an array using a while loop.
1. Write a program that checks if all elements in an array are positive numbers.
### Practice iterate control
1. Write a program that prints all odd numbers between 1 and 20 using a while loop. Use next to skip even numbers.
4. Write a program that prints numbers from 1 upwards using until, and stops when it reaches a number divisible by 7. Use break to exit.
5. Write a guessing game where the computer picks a random number between 1 and 10. The user must guess the number, and the program will give hints ("Too high" or "Too low"). Use break to stop the loop when the correct guess is made.
6. Write a program that prints even numbers between 1 and 50 using a while loop, but stops when the number 30 is reached. Use break to exit the loop when this condition is met.
7. Write a program that repeatedly asks the user for a password until they enter "ruby123". Use break to exit the loop once the correct password is entered.
8. Write a program that repeatedly asks the user for a number and checks if it is prime. Use break to exit when the user enters "exit". Use next to skip numbers less than 2.
9. Write a program that prints numbers from 1 to 20, skipping multiples of 5 using next. Use an until loop to stop once the number exceeds 20.
10. Write a program that squares numbers starting from 1 and prints them, but stops when the square exceeds 1000. Use a loop and break when the condition is met.
11. Write a program that asks the user to enter numbers and adds them to a total. If the number is divisible by 4, it skips adding it using next. The loop stops when the total exceeds 50.