Exact equality as a time-loop stop test

A student wants a simulation to advance in steps of 0.1 s and stop at exactly 1.0 s, and writes:


Python
t = 0.0
dt = 0.1
while t != 1.0:
    t = t + dt
print(t)


The program uses standard double-precision floating point. What happens when it runs?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Applications of Loops Questions: