[RUBY] Expression used in the fizz_buzz problem

Last posted fizz_buzz problem

Looking at the description, I felt that there were many basic expressions, so Let's sort out the expressions that were actually used.

Click here for the actual fizz_buzz problem explanation

fizz_buzz problem

def fizz_buzz
  num = 1
  while (num <= 100) do
    if num % 15 == 0
      puts "FizzBuzz"
    elsif (num % 3) == 0
      puts "Fizz"
    elsif (num % 5) == 0
      puts "Buzz"
      puts num
    num = num + 1


Assignment operator

Assignment operator

num = 1 #Variable name=Value to store

--Action by the above description --The value is stored in a variable using a description called assignment.

-- Substitution --You can put it in the variable box by writing = after the variable. --=` is called an assignment operator. In Ruby, an expression with one = means "assign the value on the right to the variable on the left".

--What is a variable? --A variable is like a box to put a value in. Define the variable name so that you can easily understand what kind of value is included.



num = num + 1

--Reassigning another value to the variable after assigning the value once --Can be changed as many times as you like during the program ――It is also possible to summarize briefly with the following description

Abbreviation for reassignment(Adopt self-assignment operator)

num += 1

if statement + elsif

--What is an if statement? ――You can divide the process by saying "If it is 〇〇, do △△".

Conditional branching when correct and when not

if num % 15 == 0 #Conditional expression 1
  puts "FizzBuzz" #Conditional expression 1 is true(true)Processing to be executed at

elsif (num % 3) == 0 #Conditional expression 2
  puts "Fizz" #Conditional expression 1 is false(false)+Conditional expression 2 is true(true)Processing to be executed at

elsif (num % 5) == 0 #Conditional expression 3
  puts "Buzz" #Both conditional expression 1 and conditional expression 2 are false(false)+Conditional expression 3 is true(true)Processing to be executed at

else #When not applicable
  puts num #Processing to be executed when the above conditional expression is not met

Comparison operator + algebraic operator

Comparison operator+Algebraic operator

while (num <= 100) do #Is num 100 or less?

if num % 15 == 0 #The surplus (divided remainder) is
                   #Is it equal to 0
elsif (num % 3) == 0 #The surplus (divided remainder) is
                       #Is it equal to 0
elsif (num % 5) == 0 #The surplus (divided remainder) is
                       #Is it equal to 0

-** Comparison operator **

-** Algebraic operator **


--- subtraction

--* Multiplication

--/ Division

--% Remainder (divided remainder)

Recommended Posts

Expression used in the fizz_buzz problem
Explanation of the FizzBuzz problem
Let's solve the FizzBuzz problem!
I tried the FizzBuzz problem
FizzBuzz problem
A memorandum of the FizzBuzz problem
Specify the default JAVA_HOME used in buildship
Implement FizzBuzz problem in test-driven development (preparation)
[Ruby] FizzBuzz problem
[Ruby] FizzBuzz problem
FizzBuzz in Java
Use the JDK used in Android Studio in the terminal
How to solve an Expression Problem in Java
[Java] Let's declare variables used in the loop in the loop [Variables in the block]
Pass the condition to be used in the Java8 lambda expression filter () as a parameter
I tried to organize the cases used in programming
About the problem of deadlock in parallel processing in gem'sprockets' 4.0
Source used to get the redirect source URL in Java
^, $ in Rails regular expression
Personal summary of the guys often used in JUnit 4
Try to solve a restricted FizzBuzz problem in Java
Think about the JAVA = JAVAscript problem (needed in the future)
Learn about the spec while shortening FizzBuzz written in Java
Review because I used the collection_check_boxes method in the Ralis portfolio
The case that @Autowired could not be used in JUnit5
[Question] Can nullif be used in the count function in JPQL?
Solved the problem that all the data in the table was displayed
[Note] About the Fizz_Buzz problem (How Ruby on Rails works)
Don't underestimate the N + 1 problem!
Frequently used processes in SpreadSheet
Matcher often used in RSpec
JavaFX-Load Image in the background
Solved the problem that the scroll event did not fire in JQuery
The problem that XML attributes are sorted arbitrarily in Android Studio
A memorial service for the library used when competing in Ruby
How to install the language used in Ubuntu and how to build the environment
Problem that the attribute of User model becomes nil in ActionMailer