while

There are two forms of the while filter: the standard form and the ~~ form.
    while (test) body
    while (target~~pattern body

The standard form of the while filter

In the standard form of the while filter,
  while (test) body

the test is repeatedly evaluated until it is false. After each true evaluation (that is, evaluation that matches the current position), the body is evaluated. The while filter always matches the position.

For example, the following code replaces any \n characters with space characters in a string S:

  i=0
  while (i<#S)
   {if (S[i]==\n) S[i]=" "
    i+=1}

The ~~ form of the while filter

If the test filter is a ~~ filter of the form target~~pattern then the ~~ form is used:
    while (target~~pattern body

Here, target is any string filter, and pattern is a quoted regular expression. This is discussed in more detail in ~~ while test. The above example, by the way, would look like this using the ~~ form of while:

  while(S~~\n)
   S[\-0]=" "

Here, \0 is the matched string, and \-0 is its index within S.