0

why we use mostly while loop instead of for loop in python

3rd Dec 2016, 10:15 AM
Gowtham Rajendran
Gowtham Rajendran - avatar
4 odpowiedzi
+ 2
@donkeyhot while arduino_pin_current < max_current: ?
3rd Dec 2016, 11:58 AM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Edit1: While loop is used when we stop looping on some condition or in an infinite while: True loop. In other cases use for loop: i = 0 while i<10: #C-style #do smth i += 1 for i in range(10): #pythonic #do smth
3rd Dec 2016, 12:19 PM
donkeyhot
donkeyhot - avatar
+ 1
And if you're talking about the most guys here, that use while loops mostly. That's only because they are just learning basics of python and write their programs C-style. Don't be like them. Be smart. Use for loops and other python possibilities.
3rd Dec 2016, 10:52 AM
donkeyhot
donkeyhot - avatar
0
@Kirk Schafer for arduino_pin_current in range(maxcurrent): pass Ok, i get it. You're right. While loop is also used when we stop looping on some condition. I just meant for is more common.
3rd Dec 2016, 12:15 PM
donkeyhot
donkeyhot - avatar