我有以下的PowerShell循環:PowerShell的 - 尋找Perl的重做相當於
Set-Variable -Name YELLOW -Option ReadOnly -Value 0
Set-Variable -Name ORANGE -Option ReadOnly -Value 1
Set-Variable -Name RED -Option ReadOnly -Value 2
While ($true) {
for ($color = $YELLOW; $color -le $RED; $color++) {
$LastWriteTime = ((Get-Item $FilePath).LastWriteTime)
$waitTime = (Get-Date).AddMinutes(-($WarningTimeArray[$color]))
$SleepTime = ($LastWriteTime - $waitTime).TotalSeconds
If ($SleepTime -gt 0) {
$WarningFlagArray[$color] = $false;
SendMail ("Start-Sleep -Seconds" + $SleepTime)
Start-Sleep -Seconds $SleepTime
Continue #Actually want a "redo"
}
ElseIf (-not $WarningFlagArray[$color]) {
SendMail $WarningMessageArray[$color]
$WarningFlagArray[$color] = $true
}
}
}
在PowerShell中點擊「繼續」,它繼續回到for
循環的頂部,並進入下一個顏色。
在Perl中,你有last
(相當於PowerShell的break
),你有next
(相當於PowerShell的continue
)。您也有redo
回到循環的頂部,但不增加for
循環計數器。
對於for
循環,Perl的redo
函數是否有等效的Powershell命令?
我可以很容易地將該語句轉換爲while
循環來解決這個特定問題,但我想知道是否有像redo
這樣的東西。
AFAIK,大多數語言沒有'重做'等效。 – kirilloid 2012-03-29 19:34:14
@kirilloid我知道,但在這種情況下很好。將其更改爲「while」循環。我第一次使用PowerShell。 – 2012-03-29 22:00:54