Return in function with param
12/10/2012 21:07
function hadajCislo
{ param([int]$cislo)
if($cislo -le 0)
{
return $false
}
else
{return $true}
}
$a=(1, -2, 5, 0, 4, 1, -5)
foreach($item in $a)
{
if(-not (hadajCislo -cislo $item))
{
$foreach.MoveNext()|out-null
write-host "Nubmer " $item " is not valid".
}
else
{
write-host "Nubmer " $item " is valid".
}
}
Nubmer 1 is valid .
Nubmer -2 is not valid .
Nubmer 0 is not valid .
Nubmer 1 is valid .
Nubmer -5 is not valid .
#this is like serie of validation, return causes end of function if some part is not valid.
function hadajCislo
{ param([int]$cislo)
if($cislo -le 0)
{
return $false
}
write-host "First point"
if($cislo -lt 5)
{
return $false
}
write-host "Second point"
return $true
}