by Zushakon at 2012-09-04 22:56:33
Hello,by lumm71 at 2012-09-05 00:18:27
I would like to ask a rather simple question… how do I skip one loop meaning if I check some servers for some services using loop foreach i would like to skip a loop if server is off.
You can use "continue" to end one loop:by Techibee.Author at 2012-09-05 03:00:42while ($a -lt 10)
{
$a += 1
if ($a -eq 5){continue}
Write-Host $a
}
it writes all numbers from 1 to 10 except 5 to the screen.
Is this something you are looking for?by mjolinor at 2012-09-05 04:08:58
foreach ($a in ("a","b","c","d")) {
write-host ""
Write-Host $a
foreach($b in 1,2,3,4) {
if($b -eq 3) {
Write-host "Skipping $b"
Continue
Write-Host "This will not appear"
} else {
Write-host $b
}
}
}
A simple if statement can work:by Zushakon at 2012-09-05 04:19:37
foreach ($server in $servers){
if (test-connection $server -quiet){
{
Do stuff
}
}
Continue statment works like a charm, thank You for help.
I know i could use the if statment but allready i got so many loops with diffrent if that i wanted to make it a bit easier for the eye.