Loop Concept
Loop Concept
Topics Covered:
• Loop concept (for,while)
• Break, Continue statement
`for` loops:
A `for` loop is used for iterating over a sequence (that is either a list,
tuple, dictionary, string, or range). The basic syntax is as follows:
Example:
Basic Syntax:
Output:
2
Output:
3
Output:
Important Points:
4
Output:
You can combine `range()` with `len()` to iterate over the indices of a
sequence (list, string, etc.).
5
This allows you to access both the index and the corresponding
element in the sequence.
6
`while` Loops:
Example:
• `continue` statement: Skips the rest of the code inside the loop
for the current iteration and continues with the next iteration.
7
• `pass` statement: Acts as a null operation, meaning nothing
happens when it executes. It is often used as a placeholder where
syntactically some code is required but you don't want to
execute any statements.
8
Sample Program
A)