# Silly question about loops

**URL:** <https://forums.powershell.org/t/silly-question-about-loops/129>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/silly-question-about-loops/129 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/silly-question-about-loops/129/1 "2011-12-31T18:30:00Z")

</div>

by Zushakon at 2012-09-04 22:56:33

> Hello,  
>   
> 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.

by lumm71 at 2012-09-05 00:18:27

> You can use "continue" to end one loop:  
>   
> `while ($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.

by Techibee.Author at 2012-09-05 03:00:42

> Is this something you are looking for?  
>   
> 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  
> }  
> }  
> }

by mjolinor at 2012-09-05 04:08:58

> A simple if statement can work:  
> `foreach ($server in $servers){ if (test-connection $server -quiet){ { Do stuff }}`

by Zushakon at 2012-09-05 04:19:37

> 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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:02pm UTC](https://forums.powershell.org/t/silly-question-about-loops/129/2 "2024-05-16T21:02:49Z")

</div>

Closed on May 16, 2024, 9:02pm UTC


