Skip foreach item and suppress output

13/10/2012 21:20

 

 $a=(1, 2, 5, 6, 4, 1, 5)
foreach($item in $a)
{
    if($item -ge 5)
    {
       #this causes moving to next item in foreach loop: |out-null supresses 'true' or 'false' message
       $foreach.MoveNext()|out-null
    }
    else
    {
        write-host "Nubmer " $item " is less than 5". 
    } 
}
Nubmer  1  is less than 5 .
Nubmer  2  is less than 5 .
Nubmer  4  is less than 5 .
Nubmer  1  is less than 5 .