-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy path02_control_flow.rb
149 lines (95 loc) · 1.75 KB
/
02_control_flow.rb
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
=begin
----------------
IF
----------------
=end
if 20 < 30
puts "That's true!!"
end password = "Good morning"
puts "Enter your password"
answer = gets.chomp
if answer == password
puts "You're logged in"
end
=begin
----------------
ELSE
----------------
=end
if 20 > 30
puts "That's true!"
else
puts "That's not true!"
end password = "Good morning"
puts "Enter your password"
answer = gets.chomp
if answer == password
puts "You're logged in"
else
puts "Wrong password"
end
=begin
----------------
ELSIF
----------------
=end
time = 13
if time < 12
puts "It’s before noon"
elsif time > 12
puts "It’s past noon"
else
puts "It’s noon!"
end
=begin
----------------
UNLESS
----------------
=end
password = "Hello"
puts "Please insert password"
answer = gets.chomp
unless answer == password
puts "Wrong password!"
else
puts "You're logged in!"
end
=begin
----------------
RELATIONAL OPERATORS
----------------
=end
n_1 = 16
n_2 = 20
puts n_1 <= n_2
=begin
----------------
BOELEAN OPERATORS
----------------
=end
# AND
puts "STRICT LOGIN SYSTEM - LOGS YOU IN ONLY IF BOTH THE PASSWORD AND THE USERNAME ARE CORRECT"
username = "John"
password = "Hello"
puts "Enter your username"
answer_1 = gets.chomp
puts "Enter your password"
answer_2 = gets.chomp
if answer_1 == username && answer_2 == password
puts "You're logged in!"
else
puts "Wrong credentials!"
end
# OR
puts "CHILLED LOGIN SYSTEM - LOGS YOU IN IF EITHER THE USERNAME OR THE PASSWORD ARE CORRECT"
username = "John"
password = "Hello"
puts "Enter your username"
answer_1 = gets.chomp
puts "Enter your password"
answer_2 = gets.chomp
if answer_1 == username || answer_2 == password
puts "You're logged in!"
else
puts "Wrong credentials"
end