:While and :Endwhile Commands

In command files and UDCs, you may use :While and :Endwhile commands to create program loops. See also the :If command, the /Qedit command and the INSIDEQEDIT JCW. The :While command can be nested, just like the :If command, but may not be continued with &. :While and :Endwhile cannot be used at the /-prompt or in usefiles. When used in a UDC or a command file, :While and :Endwhile can not be prefixed with a slash “/”.

:WHILE expression DO

:ENDWHILE

Examples

This example lists the line containing a search string, plus the next the three lines. To try the example, enter the following commands into Qedit and Keep them as LOOPER.

  PARM string  /set window (up)  setjcw cierror = 0  continue  /findq "!string" first  while cierror=0 do      display FOUND "!string":      /list */*+3      display      continue      /findq "!string"  endwhile  

You invoke the command file by typing the file name and the parameter:

  /open myfile  /looper alberta  /shut  

Do I Really Need to Use the :While Command?

You may not need to use the :While command. Most Qedit commands accept a rangelist, which makes it easy to include a search string in the command itself. For example, to change “oldpass” to “newpass” in all lines that contain “!job ” in the first five columns, you would

  /change "oldpass"newpass"  "!job " (1/5)  

:While and :Endwhile Commands