Here is an example of using for loop
with if statement
in Python:
main.py104 chars6 lines
Output:
main.py95 chars11 lines
In this example, the for loop
iterates through a range of 10 numbers. The if statement
checks if the current number i
is even or odd and prints the corresponding message. The %
operator is used to check if i
is divisible by 2.
You can replace the range(10)
with any iterable object in Python, such as a list or a tuple. The if statement
can also be modified according to your specific condition.
gistlibby LogSnag