A simple conditional expression, already present in
CPL in 1963, has a guard on first sub-expression, and another sub-expression to use in case the first one cannot be used. Some common ways to write this: (x>0) -> 1/x; 0 x>0 ? 1/x : 0 If the second sub-expression can be a further simple conditional expression, we can give more alternatives to try before the last
fall-through: (x>0) -> 1/x; (x -1/x; 0 In 1966
ISWIM had a form of conditional expression without an obligatory fall-through case, thus separating guard from the concept of choosing either-or. In the case of ISWIM, if none of the alternatives could be used, the value was to be
undefined, which was defined to never compute into a value.
KRC, a "miniaturized version" of
SASL (1976), was one of the first programming languages to use the term "guard". Its function definitions could have several clauses, and the one to apply was chosen based on the guards that followed each clause: fac n = 1, n = 0 = n * fac (n-1), n > 0 Use of guard clauses, and the term "guard clause", dates at least to
Smalltalk practice in the 1990s, as codified by
Kent Beck. This example, in APL, computes the parity of the input number: parity←{ 2∣⍵ : 'odd' 'even' } ==Pattern guard==