Conditional branching of numbers

I would like to create a program that inputs numbers from the terminal and changes the processing according to the numbers.

If it is +10 or less, it is "a number of 10 or less"

Create a program that can output like this.

First, enter a number from the terminal and assign it to a variable.

input = gets.to_i

All the values ​​entered using the gets method are strings, so even if you enter numbers, they will be converted to strings when used in the program. Therefore, I use the to_i method to convert it to a number.

Next, we will make a conditional branch using the if statement. Since the if statement makes a judgment based on the conditions written earlier, it will be passed through even if the conditions written below it are met.

We will consider the order with this rule in mind.

input = gets.to_i

if input <= 0
  puts "It is a number less than 0"
elsif input <= 10
  puts "Is a number less than 10"
else
  puts "Is a number greater than 10"
end

By writing in this order, even if a number of 0 or less is input, it will not be output if the number is 10 or less.

Recommended Posts

Conditional branching of numbers
Basics of conditional branching and return
Program using conditional branching
This and that of conditional branching of rails development
Also complicated conditional branching
[Ruby] Conditional branching Conditional expression order
A little complicated conditional branching
java (conditional branching and repetition)
Conditional branching with a flowing interface
Java study # 4 (conditional branching / if statement)
[Java] Implicit type cast (AOJ10-sum of numbers)
[Java] Personal summary of conditional statements (basic)
[Ruby] if statement concept of conditional expression
Convert an array of strings to numbers
[Java ~ Conditional branching / Iterative processing ~] Study memo (3)
Basics of Java development ~ How to write a program (flow and conditional branching) ~
Conditional branching of the result of SQL statement to search only one in Java