Program using conditional branching

I don't want Pepper to speak from 20:00 to 6:00 the next morning, so I'll create a method that outputs "NG" during that time and "OK" otherwise. Set the time when Pepper speaks to true and the time when he does not speak to false, and enter the time at the same time.

An example output is

pepper_talk(true, 5)
=>NG
pepper_talk(true, 6)
=>OK
pepper_talk(false, 5)
=>OK
pepper_talk(false, 5)
=>OK

It is such an image.

First, create a method.

def pepper_talk(talking, hour)

end

I will write the process so that it becomes an output example. I think it's a good idea to divide the time when you shouldn't speak from 0:00 to 6:00 and after 20:00.

def pepper_talk(talking, hour)
  if talking && (hour < 6 || hour >= 20 )
    puts "NG"
  else
    puts "OK"
  end
end

Recommended Posts

Program using conditional branching
Realize a decision table without using conditional branching
Try using conditional branching other than if statement
Conditional branching of numbers
Also complicated conditional branching
Ruby study memo (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] "Setting" using Enum rather than conditional branching by if statement -Strategy Enum
[Java ~ Conditional branching / Iterative processing ~] Study memo (3)
Basics of Java development ~ How to write a program (flow and conditional branching) ~