Tools: MPW
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

MPW Command Reference


For…

Built-in

SYNTAX

For name In parameter1 [parameter2]…
  command1
  [command2]…
End

DESCRIPTION

The For… command is a loop control structure that executes the list of commands once for each parameter in the parameter list. Note that as it loops, For… assigns the current parameter to the variable name. This allows you to reference the parameter in your list of commands by using the variable {name}.

Note
Be sure to end each line with either a return character or a semicolon. To prematurely terminate the loop, use the Break command. To terminate only the current iteration of the loop, use the Continue command. •

You can use pipe specification (|), conditional command terminators (&& and ||), and redirection operators (<, >, >>, ≥, ≥≥, ∑, and ∑∑), as long as they appear after End. When used in this manner, these special characters apply to all the commands in the list.

INPUT

None

OUTPUT

None

STATUS

For… can return the following status codes:

0

list of words or commands is null

-3

parameter error

n

status code returned by the last command executed

PARAMETERS

command1 [command2]…

Specifies a list of commands to be executed once for each parameter.

name

Specifies the name of the variable to which the current parameter is assigned. This allows you to reference the parameter in your list of commands by using the variable {name}.

parameter1 [parameter2]…

Specifies a list of parameters, one for each iteration of the For… loop.

OPTIONS

None

EXAMPLES

In this example, the simple loop

For i In 1 2 3
  Echo i = {i}
End

returns the following:

i = 1
i = 2
i = 3

The following example compiles every file in the current directory whose name ends with a ".c" suffix. To do this, the MPW Shell first expands the filename pattern ≈.c, creating a list of the filename parameters. The enclosed commands are then executed once for each parameter in the list. Each time the loop is executed, the variable {File} represents the current parameter in the list. Note that {File} is enclosed in quotation marks in case the expanded filename contains spaces or other special characters.

For File In ≈.c
  MrC "{File}" ; Echo "{File}" compiled.
End

The following example replaces multiple spaces with tabs (Entab) in the four files listed and prints them with headings. The name of each file is echoed after printing is complete.

For file in UserStartup•Mine Suspend Resume Quit
  Entab "{file}" > temp
  Rename -y temp "{file}"
  Print -h "{file}"
  Echo "{file}"
End

You might want to use this set of commands, for instance, before making copies of the files to give to a friend. Putting tabs into the files saves considerable disk space, and printing them gives you some quick documentation to go with the files.

SEE ALSO

Break

Continue

Loop…End

 
 


Last Updated July 2000