For loop Syntax Python
Syntax:
for variable in iterable:
# Code block to be executed repeatedly for each element in the iterable
Explanation of the Syntax:
- Python’s
for
loop iterates over the elements of an iterable object, such as lists, tuples, strings, etc. - It assigns each element of the iterable to the specified variable and executes the code block for each element.
- The loop continues until all elements of the iterable have been processed.
Implementation of For loop Syntax in Python:
Python3
# For loop for i in range ( 10 ): print (i, end = " " ) |
Output
0 1 2 3 4 5 6 7 8 9
For loop Syntax
For loop is a control flow statement in programming that allows you to execute a block of code repeatedly based on a specified condition. It is commonly used when you know how many times you want to execute a block of code.
Table of Content
- For loop Syntax in C/C++
- For loop Syntax in Java
- For loop Syntax Python
- For loop Syntax in C#
- JavaScript (JS) For loop Syntax
The syntax of For loop varies slightly depending on the programming language, but the basic structure is similar across many languages.
for (initialization; condition; update) {
// Code block to be executed repeatedly as long as the condition is true
}
Here’s a general overview of the Syntax of For loop:
- Initialization: This is where you initialize the loop control variable. This variable is typically used to keep track of the current iteration of the loop.
- Condition: This is the condition that is evaluated before each iteration of the loop. If the condition is true, the loop continues; otherwise, it terminates.
- Update: This is where you update the loop control variable. Typically, you increment or decrement the variable to ensure progress toward the loop termination condition.
Contact Us