Syntax: for
for variable in iterable: # Code block to execute
Python program that demonstrates the use of for loop
# Example program using a for loop for i in range(1, 6): print(i)
Outout
1 2 3 4 5
Loop: A loop is a control flow statement that allows code to be executed repeatedly based on a condition. It helps automate repetitive tasks by iterating over a block of code until a specified condition is met.
For Loop: A for loop in Python is used to iterate over a sequence (such as a list, tuple, or string) or other iterable objects. It executes a block of code for each item in the sequence.
Syntax: for
for variable in iterable: # Code block to execute
# Example program using a for loop for i in range(1, 6): print(i)
Outout
1 2 3 4 5