RosettaCodeData/Task/Menu/PowerShell/menu-1.psh

12 lines
293 B
Plaintext

function Get-Choice ([array] $Items) {
Set-StrictMode -Version Latest
do {
$Items | ForEach-Object { $i = 0 } { '{0,3}. {1}' -f (++$i),$_ }
$choice = Read-Host Your choice
} while ($choice -notmatch '^\d+$' -or
!(1..$Items.Length -eq $choice))
$Items[$choice-1]
}