Programs · Program 6-10
Q.Program 6-10: Program to print first 5 natural numbers using while loop.
Punjab PsebTextbookSubjective· 2mImportance★★★★★est
36% · 14/39 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Initialise a counter to 1, loop while count <= 5: printing and incrementing it — the loop prints 1 2 3 4 5 and stops when the counter reaches 6.
The idea. A while loop is condition-controlled: it keeps repeating as long as a Boolean expression stays True. To count with it you must manage the counter yourself — initialise it before the loop, test it in the condition, and update it inside the body. (A for loop does all three for you; this program shows the manual version.)
# Program 6-10: print the first 5 natural numbers using a while loop
count = 1
while count <= 5:
print(count)
count += 1
Expected output
1
2
3
4
5
Dry run
| Pass | count at test | count <= 5 | Printed | count after += 1 |
|---|---|---|---|---|
| 1 | 1 | True | 1 | 2 |
| 2 | 2 | True | 2 | 3 |
| 3 | 3 | True | 3 | 4 |
| 4 | 4 | True | 4 | 5 |
| 5 | 5 | True | 5 | 6 |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.