What is the difference between a cycle "if" and "while"?

Both commands are used to run a chunk of code that satisfies the condition inserted. The main difference is that while is a loop, i.e. it is run until the condition is satisfied, while if stops in every case. The two commands have the same objective, however if is usually used when you know exactly how many times you want to test the condition.

FN

Related Python Mentoring answers

All answers ▸

How would you get a piece of code to print the numbers 1 to 10


Create a program that checks for syntactical errors in an email address.


What is the difference between using range() and a list of values?


Explain how you would write a python program that takes a rectangle and a point in a 2D space as command-line arguments and checks if they intersect.