Ch 6 covers the three fundamental control structures: sequential (default), selection (if-elif-else for decision making), and iteration (for and while loops for repetition). Also covers break, continue, pass, and the else clause with loops.
if statement: if condition: block. if-else: two branches. if-elif-else: multiple conditions checked in order — first True branch executes. Nested if: if inside if for multi-level decisions. Ternary: x = "Even" if n%2==0 else "Odd". Conditions use comparison (<, >, ==, !=) and logical operators (and, or, not). Python indentation (4 spaces) defines blocks — no braces. Common errors: = vs ==, missing colon, wrong indentation.
for loop: for var in sequence (list, string, range). range(n): 0 to n-1. range(start, stop): start to stop-1. range(start, stop, step): custom step. while loop: while condition: block — repeats until condition is False. Infinite loop: while True (use break to exit). break: immediately exit innermost loop. continue: skip rest of current iteration, proceed to next. pass: does nothing — placeholder. else with loop: else block runs ONLY when loop finishes normally (no break). Nested loops: loop inside loop — inner completes for each outer iteration.
Download: https://ncert.nic.in/textbook/pdf/kecs106.pdf | Complete Book: https://ncert.nic.in/textbook/pdf/kecs1ps.zip
The else clause of a for or while loop executes when the loop finishes normally — i.e., without encountering a break statement. If break is triggered, the else block is skipped. Use case: searching — loop through items, break if found; else: "not found." Example: for i in range(2, n): if n%i==0: print("Not prime"); break; else: print("Prime"). The else here runs only if no factor was found (no break). It's a Python-specific feature, not found in most other languages.
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →