Programming Tip -How to use multiple for and while loops together in Python?

in #utopian-io6 years ago

Programming Tip -How to use multiple for and while loops together in Python?

EBOOK_PYTHON_no-name.png


Today i am going to show Programming Tip -How to use multiple for and while loops together in Python
with simple code. I hope you will understand this.
If you have any query you can ask.
i hope you will like it.


You can even nest a for loop inside a while loop or the other way around. For example,

for i in range(5):
   j = i
   while j != 0:
      print(j, end=', ')
      j -= 1
   print("")


This will give the output

1,
2, 1,
3, 2, 1,
4, 3, 2, 1,
You can take this nesting to as many levels as you like.


Follow me at : https://steemit.com/@ahmadhassan
=========================================================


Thanks for reading and always welcome your suggestions :) =========================================================

Sort:  

This post has received a 1.78 % upvote from @booster thanks to: @ahmadhassan.