title: Traffic light program using while loop in python
body: <p>I am trying to run this code in python and I want the code to stop looping when the user enters 30, here I have used break to stop the loop, is there any other way? Any suggestion would be helpful. </p>
  
  <pre><code>`x = input("Enter value: ")
  stop_light = int(x)
  while True:
      if stop_light &gt;= 1 and stop_light &lt; 10:
          print('Green light')
          stop_light += 1
      elif stop_light &lt; 20:
          print('Yellow light')
          stop_light += 1
      elif stop_light &lt; 30:
          print("Red light")
          stop_light += 1
      else:
          stop_light = 0
      break`
  </code></pre>