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

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Powershell,
- PowerShell: How to Check if a Module is Already Installed
- PowerShell: How to Write Output to a File
- PowerShell: Steps to Connect to connect to Exchange Online
- PowerShell Fix: Get-Help cannot find the Help files for this cmdlet on this computer
- PowerShell Traditional For Loop Example
- How to Run PowerShell Script as Administrator (Elevate)
- Update Powershell Using Command Line
- How to delete a file using PowerShell [Windows/macOS]
- PowerShell: Grep Command Alternative - Select-String
- PowerShell Concatenate String Examples
- How to add Sleep to PowerShell Script
- Connect Azure AD (Active Directory) for PowerShell
- How to Open PowerShell on Mac?
- List of PowerShell Function Commands for Mac
- How to Connect to Azure AD Account using PowerShell on Mac
- Download Google Chrome setup exe file using PowerShell
- Set Environment Variable in PowerShell for Mac
- How to switch to Powershell on Mac Terminal
- How to add sleep in Powershell Script
- PowerShell on Mac: The term get-service is not recognized as a name of a cmdlet, function, script file, or executable program
- How to Identify installed PowerShell version
- How to check PowerShell version
- How to install PowerShell on Mac using Brew
- PowerShell Switch Statement with Examples
- PowerShell ISE Alternative for Mac
More Posts:
- Remove Trailing zeros BigDecimal Java - Java
- How to change background color in Notepad++ - NotepadPlusPlus
- How to Create Absolute References in Microsoft Excel for Mac - Microsoft
- 🎃 Trending, Popular Halloween hashtags for year 2020 🎃 [Facebook, Twitter, Instagram, Snapchat] - Hashtags
- How to refresh Safari on Mac (macOS) using keyboard shortcut - MacOS
- How to empty Trash in macOS? - MacOS
- Bash Command to Check Python Version - Bash
- Android SecurityException: Need BLUETOOTH ADMIN permissicacheNameAndAddresson: Neither user 10123 nor current process has android.permission.BLUETOOTH_ADMIN - Android