The traditional for loop is the one you may find in almost all programming languages like C, C++, Java, and so on.
If you are wondering if there is such a for loop in PowerShell, well Yes! Let's take a look at the Syntax and an example.
Syntax:
for (<initialization>; <condition>; <increment>) {
# Your code within for loop
}
PowerShell For Loop Example:
# For Loop from 1 to 10
for ($i = 1; $i -le 10; $i++) {
Write-Host "Number: $i"
}
Output:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
Number: 6
Number: 7
Number: 8
Number: 9
Number: 10

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!