-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops2_practice_problems.rb
More file actions
107 lines (76 loc) · 1.83 KB
/
Copy pathloops2_practice_problems.rb
File metadata and controls
107 lines (76 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 1. Write a while loop to print the numbers 1 through 10.
puts "Problem 1:"
number = 1
while number <= 10
p number
number = number + 1
end
# 2. Write a while loop that prints the word "hello" 5 times.
puts "Problem 2:"
i = 1
while i <= 5
puts "hello"
i += 1
end
# 3. Write a while loop that asks the user to enter a word and will run forever until the user enters the word "stop".
puts "Problem 3:"
# while true
# puts "Enter a word:"
# word = gets.chomp
# if word == "stop"
# break
# end
# end
# 4. Write a while loop that prints the numbers 0 through 100, increasing by 5 each time.
puts "Problem 4:"
number = 0
while number <= 100
p number
number = number + 5
end
# 5. Write a while loop that prints the number 9000 ten times.
puts "Problem 5:"
i = 0
while i < 10
p 9000
i += 1
end
# 6. Write a while loop that asks the user to enter a number and will run forever until the user enters a number greater than 10.
puts "Problem 6:"
# while true
# puts "Enter a number:"
# number = gets.chomp
# if number.to_i > 10
# break
# end
# end
# 7. Write a while loop that prints the numbers 50 to 70.
puts "Problem 7:"
number = 50
while number <= 70
p number
number = number + 1
end
# 8. Write a while loop that prints the phrase "Around the world" 144 times.
puts "Problem 8:"
i = 0
while i <= 144
puts "Around the world"
i += 1
end
# 9. Write a while loop that asks the user to enter a word and will run forever until the user enters a word with more than 5 letters.
puts "Problem 9:"
while true
puts "Enter a word"
word = gets.chomp
if word.length > 5
break
end
end
# 10. Write a while loop that prints the even numbers from 2 to 40.
puts "Problem 10:"
number = 2
while number <= 40
p number
number = number + 2
end