Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created September 6, 2018 13:14
Show Gist options
  • Save pknowledge/346dd48fb84275581c16d12e867ef565 to your computer and use it in GitHub Desktop.
Save pknowledge/346dd48fb84275581c16d12e867ef565 to your computer and use it in GitHub Desktop.
while Loop
# Python Tutorial for Beginners - while Loop
#--------- Example 1 ---------------
i = 0
while True:
print("the value of i is : ", i)
i += 1 # i = i + 1
else:
print("Finished while loop")
#--------- Example 2 ---------------
num = 1
sum = 0
print("Enter a Number. Please Enter zero(0) to exit")
while num != 0:
num = float(input("Number ? "))
sum = sum + num;
print("sum = ",sum)
else:
print("Finished sum")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment