⚡0 XP🔥0

Ch 6 · Flow of Control | प्रवाह नियंत्रण

Lesson 6 of 11 ⏱ 3 min read ✎ 1 exercises ❓ 5-question quiz ▶ Runs Python

Selection with if, if-else, if-elif-else and nested if; iteration with for and while loops, range(), break, continue and nested loops; common programs.

Selection#

▶ Try it YourselfPython
Ctrl + Enter to run

Indentation defines blocks in Python.

Iteration#

  • for loop with range(start, stop, step) - stop is excluded.
  • while loop runs as long as the condition is true.
  • break exits the loop; continue skips to the next iteration.
▶ Try it YourselfPython
Ctrl + Enter to run
हिंदी में समझें

if-elif-else से शर्तों के अनुसार निर्णय लिए जाते हैं। for लूप range() के साथ निश्चित बार चलता है और while लूप शर्त सही रहने तक। break लूप से बाहर निकालता है और continue अगली पुनरावृत्ति पर ले जाता है।

Common programs#

Prime check, factorial, Fibonacci series, palindrome number, Armstrong number, patterns with nested loops.

▶ Try it YourselfPython
Ctrl + Enter to run

Exam tips#

  • Output questions with range() steps and break/continue are very common.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

Prime or not

Read an integer n (n ≥ 2) and print Prime if it is prime, otherwise Not Prime.

Test input:
29
Expected output:
Prime

Quick Quiz

Q1.

range(2, 10, 3) gives

Q2.

Keyword to exit a loop early is

Q3.

Python defines blocks using

Q4.

continue causes the loop to

Q5.

How many times does 'for i in range(5)' run?