[RUBY] Volume that wants to use a lot of logical operators in if statements

Introduction

I will summarize how to use logical operators when you want to overlap conditions in if statements that you learned today.

Logical operator

&& → and Example

if a && b
#processing
end

When both a and b are true, the process is executed.

||→ or Example

if a || b
#processing
end

If either a or b is true, the process is executed.

!a true and false are opposite. Example

if !a
#processing
end

If a is really false, the process is executed. (Because false changes to true)

Use multiple logical operators in if statements

Simply put, use () to tie up a unit.

Example


if ( a && b ) || ( !a && !b )
#processing
end

||Therefore, if the left side or the right side is true, the process is executed. If the left side is "a and b is true", the left side as a whole becomes true. If the right side is "a and b are really false", the right side as a whole becomes true. The point is that if a and b match with true or false, the process will be executed. </ font>

at the end

It's like what I did in high school number A ...

Recommended Posts

Volume that wants to use a lot of logical operators in if statements
[Spring Boot] If you use Spring Boot, it was convenient to use a lot of util.
How to use named volume in docker-compose.yml
[Swift] If you want to use a URL that includes Japanese, use addingPercentEncoding.
How to use JQuery in js.erb of Rails6
What to do if you get a wrong number of arguments error in binding.pry
I want to use PowerMock in a class that combines parameterized tests and ordinary tests
Use a binary search to see if there are any values in the array
I want to use a little icon in Rails
Things to keep in mind when using if statements
[Rails] Volume that displays favorites and a list of favorites
How to use CommandLineRunner in Spring Batch of Spring Boot
When I switched to IntelliJ, I got a lot of differences in the encoding of the properties file.
A note that I had trouble when trying to use nginx with Remote-Containers of vscode
With podman in docker, everyone wants to get along and use docker on a shared computer
Evaluation of logical operators
Change driver to Rack :: Test if driver wants to POST in Selenium test
What to do if you get a java.io.IOException in GlassFish
Port C code with a lot of typecasts to Swift
Determine that the value is a multiple of 〇 in Ruby
How to create a placeholder part to use in the IN clause
A program that counts the number of words in a List
I tried to make a client of RESAS-API in Java
[Enum_help] Use enum_help to create a select box displayed in Japanese!
[Swift] When you want to know if the number of characters in a String matches a certain number ...
How to make a key pair of ecdsa in a format that can be read by Java
[Java] What to do if a lot of "File is opened too much" is displayed due to FileNotFoundException
If you want to mock a method in RSpec, you should use the allow method for mock and the singleton method.