title: Getting user input till I meet a condition in python
body: <p>I'm trying to write a code where the program keeps getting the user input in integers and adds it to an empty array. As soon as the user enters "42", the loop stops and prints all the collected values so far.</p>
  
  <p>Ex:<br/>
  <strong>Input:</strong></p>
  
  <pre><code>1
  2
  3
  78
  96
  42
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>1 2 3 78 96
  </code></pre>
  
  <p>Here is my code (which isn't working as expected):</p>
  
  <pre><code>num = []
  
  while True:
    in_num = input("Enter number")
    if in_num == 42:
      for i in num:
        print (i)
      break
    else:
      num.append(in_num)
  </code></pre>