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

in #utopian-io8 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:  

Awesome post!! Keep it up and check out THIS POST as well as I have something similar.

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

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.083
BTC 62069.28
ETH 1614.34
USDT 1.00
SBD 0.45