4.2.1–4.2.2
while and for loops (4.2.1–4.2.2) is a Class 10 Computer Science lesson for the Punjab boards. It walks through the idea in plain steps, then sets a short check, in English, Urdu or Roman Urdu.
Your guide: Miss HiraExplains computers with chai, cricket and your phone.
Chapter 1 of every subject is free. Unlock every chapter of this class with the full course.
Unlock full courseAlready paid? Sign in with the Google account you paid with.
A while loop repeats while its condition is True, checking before each pass. number = 1; while number < 10: print(number); number += 1 prints 1 to 9.
Forget number += 1 and the condition never becomes False: an infinite loop.
A for loop goes through each item of a sequence such as a list or string: for friend in friends: print("Welcome to", friend) greets Sami, Raza and Moosa.
Step 1 / 1
A while loop repeats while its condition is True, checking before each pass. number = 1; while number < 10: print(number); number += 1 prints 1 to 9.
Forget number += 1 and the condition never becomes False: an infinite loop.
A for loop goes through each item of a sequence such as a list or string: for friend in friends: print("Welcome to", friend) greets Sami, Raza and Moosa.
while: repeat until a condition fails. for: repeat once per item.
Found a mistake? Tell us the lesson and the line at exciting@boringeducation.com.
No ads. Tell us what to fix.