FOR Loop in PowerShell
In the beginning, we need to understand the comparison operators
-eq #equal =
-ne #not equal !=
-gt #greater than >
-lt #less than <
-le #less than or equal <=
-ge #grater than or equal >=
1) How to use For Loop in PowerShell?
for($i = 0; $i -lt 5; $i++){
$i
}
Output:
0
1
2
3
4
2) How to use While Loop in PowerShell?
$i=1
While ($i -le 5){
$i
$i++
}
Output:
1
2
3
4
5
3) How to use Foreach Loop in PowerShell?
$numbers = 22,5,10,8,12,9,80
foreach($number in $numbers){
if($number -le 10){
$number
}
}
Output:
5
10
8
9