If you would not be assigning a value to that variable in each iteration, you would need it defined outside loop - same as you already do with secret_number variable.
Originally posted, but is incorrect, as pointed out by buran:
Originally posted, but is incorrect, as pointed out by buran: