-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3controlFlow.rb
More file actions
53 lines (40 loc) · 1.18 KB
/
3controlFlow.rb
File metadata and controls
53 lines (40 loc) · 1.18 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
# Note your can check multiple conditions by using && (and) and || (or) operators
if false
puts 'nice'
else
puts 'oh no !'
end
puts 'Hi, rubyer !' if true # Conditions can also be wrote at the end (not need to end in this case)
# Reverse a condition using the exclamation mark (!)
puts 'Ruby is cool...' if !false
# The unless operator executes code if conditional is false. (unless is equivalent to !condition)
# If the conditional is true, code specified in the else clause is executed.
unless false
puts 'Yukihiro Matsomoto done a great job !'
else
puts 'I love the language anyway !'
end
a = 0
while a < 10
puts a
a += 1
end
for i in 1..10 # use 1...10 in the range to exlcude the last number
next if i == 4 # continue (ignore the rest of instructions & go to next iteration)
puts i
end
students = ['Bob', 'Jacques Lombard', 'Simon']
computers = {mac: [name: 'Mac', storage: 'SSD 500gb', ], pc: [name: 'HP', storage: 'HDD 250gb']}
computers.each do |key, value|
puts "#{key}: #{value}"
end
students.each do |student|
puts student
end
3.times.each do |value|
puts value
end
# Blocks signature:
# ... do |optional_parameter1, parameter2, etc|
# Iteration on params
# end