1
@dfa = Time.new
@type_me = gets
@i = 0
def type
  pause_duration = 2
  start_time = Time.new
  until Time.new == start_time + pause_duration
  puts "#{start_time + pause_duration} || #{Time.new}"
  end
  print @type_me[@i]
  @i += 1
  type
end

type

Why isn't Time.new ever equal to start_time + pause_duration?

cyclingLinguist
  • 334
  • 1
  • 5
  • 16

2 Answers2

1

You're just not likely to get them with the same microsecond precision in the loop. Use >= instead.

pguardiario
  • 53,827
  • 19
  • 119
  • 159
1

It is not that they are never equal. It is that it is very rare that they become equal. The loop takes time for each iteration. You are only comparing times with that increment, which does not necessarily add up to exactly 2.0 seconds at any point.

sawa
  • 165,429
  • 45
  • 277
  • 381