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 ▸

Print "Hello World!" ten times without typing (or pasting) the print function more than once


How can you take a list of numbers and add 3 to every number in the list using only one line of code?


Whats is the difference between a function and a procedure?


Create an rock, paper, scissors game. The user should input one option, and the computer should play randomly.