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.

Answered by Federico N. Python tutor

986 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

What does __init__ mean?


Use recursion to print all the sublists of a given list


Sales is real Customers is integer startmainprog input Sales input Customers if ((Sales > 500) OR ((Sales > 300) AND (Customers>9))) then output “Bonus Awarded” else output “No Bonus” end if end subroutine. Sales = 600 Customers = 9, answer:


Implement a fibonacci function which calculates the nth number of the fibonacci sequence.


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo
Cookie Preferences