‘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<TAB>.

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!

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
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
    }
}

One Response to “‘Whilst’ keyword in PowerShell”

  1. J J J writes:

    J has both a ‘while’ and also a ‘whilst’ keyword! No joke. Well, maybe it is. But still, this is indeed part of that language.

Leave a Reply