Snippets Collections
 #declare two set the range
1.i = 1
2.j = 5
#use while loop for i
3.while i < 4:
#use while loop for j    
4.while j < 8:
        5.print(i, ",", j)
        6.j = j + 1
        7.i = i + 1
Output:
1 , 5
2 , 6
3 , 7                               
                                
days = 0
week = [‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’, 3.‘Sunday’]
while day < 7:
print(“Today is” + week[days])
days += 1
                                
                                
# Program to add natural
# numbers upto 
# sum = 1+2+3+...+n

# To take input from the user,
# n = int(input("Enter n: "))

1.n = 10

# initialize sum and counter
2.sum = 0
3.i = 1

4.while i <= n:
   5. sum = sum + i
   6. i = i+1    # update counter

# print the sum
7.print("The sum is", sum)

When you run this code output will be:
Enter n: 10
The sum is 55
bookmark
dashboard

Tue Apr 21 2020 06:12:11 GMT+0000 (UTC) https://beginnersbook.com/2018/01/python-while-loop/

#python #python #loop #whileloop #nestedwhile loop
bookmark
dashboard

Tue Apr 21 2020 05:36:09 GMT+0000 (UTC) https://www.freecodecamp.org/news/python-example/

#python #python #loops #whileloop
bookmark
dashboard

Tue Mar 31 2020 11:54:39 GMT+0000 (UTC) ttps://www.programiz.com/python-programming/while-loop

#python #pyhton #loops #whileloop

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension