Dec-29-2020, 02:35 AM
Hi folks! I'm a beginner and at the moment I'm taking a course of loop control in python. One of examples of how to implement continue instruction in a loop was this:
Thank you!
largest_number = -99999999 counter = 0 number = int(input("Enter a number or type -1 to end program: ")) while number != -1: if number == -1: continue counter += 1 if number > largest_number: largest_number = number number = int(input("Enter a number or type -1 to end program: ")) if counter: print("The largest number is", largest_number) else: print("You haven't entered any number.")What I don't understand is why is it needed there at all? same for the if number == -1: condition? what function does it perform? and Isn't 'while' condition enough to carry out the task?
while number != -1: counter += 1seems to be working fine without them..?
Thank you!