0

is there any big difference between if and while?

w = input("Enter weight:") da = input("Enter direction of airflow:") a = input("Enter accelration:") k = input("Enter constant of airflow:") while((w!=0 or da!=0 or a!=0 or k!=0)): if( a == 0 or k == 0): print("input value error -- please re-enter correct values") else: ra = deg_rad(da) wn = pounds_to_newtons(w) v = velocity(wn, ra, k) t = time1(v,a) p = position (t,a) print(p) -------------------------------------------- why wouldn't we just use if statement instead of while? is while loop important there? thanks

10th Dec 2016, 5:00 AM
Jacob
2 ответов
+ 4
I might be wrong here, but "if" kinda only does it once, while "while" does it repetitively so long as it's true.
10th Dec 2016, 5:23 AM
Ahri Fox
Ahri Fox - avatar
+ 1
While loops are going to execute the code repeatedly until the conditions evaluates to false. The if () statement will just execute once if the condition is true. If you want to execute the code under the while loop a couple of times you should keep it as is. Remember that it will loop forever until you evaluate the conditions to false, since you are using 'or' operators if one of them evaluates to true it will keep looping. Check this example that I did: https://code.sololearn.com/c2lJdH32giol
10th Dec 2016, 5:48 AM
Rodrigo Monney
Rodrigo Monney - avatar