Hi Readers,
In this we are going to learn conditions and Iterators in Ruby. Please follow the below concepts.
In this we are going to learn conditions and Iterators in Ruby. Please follow the below concepts.
if, unless, and the ? Operator
message = if count > 10
"Try again"
elsif tries == 3
"You lose"
else
"Enter command"
end
raise "Unauthorized" if !current_user.admin?
raise "Unauthorized" unless current_user.admin?
status = input > 10 ? "Number too big" : "ok"
"Try again"
elsif tries == 3
"You lose"
else
"Enter command"
end
raise "Unauthorized" if !current_user.admin?
raise "Unauthorized" unless current_user.admin?
status = input > 10 ? "Number too big" : "ok"
Iterators: while, until, for, break, and next
while count < 100
puts count
count += 1
end
payment.make_request while (payment.failure? and payment.tries < 3)
for user in @users
next if user.admin?
if user.paid?
break
end
end
until count > 5
puts count
count += 1
end
puts count
count += 1
end
payment.make_request while (payment.failure? and payment.tries < 3)
for user in @users
next if user.admin?
if user.paid?
break
end
end
until count > 5
puts count
count += 1
end
Practice with different conditions,
Please share this to help others.
No comments:
Post a Comment