A SCAN statement has the form
SCAN character-expression,starting-position:last-start,ending-pos ition; [value,value]:alt,value:alt...
and performs an alt corresponding to a value that matches the character-expression at the first possible position within that expression for a match. Any match must be within the starting and ending positions, and must start before the last-start position, if these positions are given, where the first character has position 1, the second position 2, and so on. 0 can also be used to refer to the last character of the string, -1 to its second-last character, and so on.
Here, the @-comments are
SCAN character-expression @FROM, starting-position @TO: last-start @UNTIL, ending position @FINDING; value @THEN: alt @OR,...
and @OR, becomes &'FINDING' and @UNTIL, &'UPTO' to avoid operator and keyword conflicts, these versions also being suitable @-comments
Thus, in the statement
SCAN 'MY CONGRATULATIONS TO YOU'; 'RAT': {. X=1}, 'CON': {. X=2}, 'CONGRA': {. X=3}
we can say that X will not be given the value 1, although 'RAT' is in the source string; however, whether X will be 2 or 3 as the result of this statement is not specified.
Note that the values and the character-expression may also be PATHs.
The predefined function _SPOS returns the character position at which the most recent SCAN has succeeded, which may be useful.
Like CASE, SCAN has the corresponding ORDSCAN (OSCAN) statement.