'Whilst' keyword in PowerShell
Recently, SMBC Comics made the comment that, “In Britain, they have whilst loops, which do not terminate until the Queen says it’s appropriate.”
If you are a programming language aficionado, you may recognize this keyword chiefly from languages of P-Celtic (especially Common Brythonic) origin.
One thing you may not know is that the PowerShell team has a huge Canadian contingent. There have been many Canadians responsible for PowerShell’s success, and early tab completion implementations automatically expanded “o” to “ou”. For example, Set-ConsoleColo.
Those never made it into the product, but the official pronunciation of the about_* help topics continues to be (IPA əbʌʊt).
That said, how do you get the well-known ‘whilst’ keyword in PowerShell? With the new Invoke-WebRequest cmdlet in PowerShell version three, this is a breeze!
function whilst
{
<#
.SYNOPSIS
Iterates over $scriptblock as long as the
Queen says to.
.EXAMPLE
whilst "Changing the guard" { "Hello World" }
#>
param(
## The status to check for
$status,
## The action to invoke
$scriptblock
)
$r = iwr twitter.com/BritishMonarchy
while(
($r.ParsedHtml.getElementById("timeline").getElementsByTagName("p") |
Select -First 1).InnerText -match $status
)
{
& $scriptBlock
Start-Sleep -Seconds (10 * 60)
$r = iwr twitter.com/BritishMonarchy
}
}