[RUBY] Try using conditional branching other than if statement

In addition to the if statement, there is also a method called unless for conditional bifurcation in Ruby. If the conditional expression is true, the if statement is executed, and if it is false, the process described after else is executed.

if conditional expression
Processing to be executed when the conditional expression is true
else
Processing to be executed when the conditional expression is false
end

In the unless statement, the process is executed when the conditional expression is false, and when it is true, the process described after else is executed.

unless conditional expression
Processing to be executed when the conditional expression is false
else
Processing to be executed when the conditional expression is true
end

For example

if a + b > 0
  puts "The calculation result is greater than 0"
end

If you write the if statement of, using the unless statement,

unless a + b <= 0
  puts "The calculation result is greater than 0" 
end

Since 0 is not included in the if statement, setting it to 0 or more in the unless statement has the same meaning.

Recommended Posts

Try using conditional branching other than if statement
[Java] "Setting" using Enum rather than conditional branching by if statement -Strategy Enum
Java study # 4 (conditional branching / if statement)
Program using conditional branching
[Ruby] conditional branch if statement
[Introduction to Java] Conditional branching (if statement, if-else statement, else if statement, ternary operator, switch statement)
[Java] Conditional branching is an if statement, but there is also a conditional operator.
[Ruby] if statement concept of conditional expression
if statement
Realize a decision table without using conditional branching
Try using libGDX
Try using Maven
Try using powermock-mockito2-2.0.2
Try using GraalVM
Try using jmockit 1.48
Try using sql-migrate
Try using SwiftLint
Try using Log4j 2.0