While Loops
while condition:
# code block to be executed
# condition is evaluated again at the end of the loop# Program to add natural
# numbers up to nth term
# sequence: total = 1 + 2 + 3 + ... + n
# initialize total and counter
total = 0
counter = 1
n = int(input("Enter the value of n: "))
# calculate total of first n natural numbers
while counter <= n:
total = total + counter
counter = counter + 1
# display the total
print(f"The sum is {total}")Last updated
