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

MPW Command Reference


If…

Built-in

SYNTAX

If expression
  command1
  [command2]…
[Else If expression
  command1
  [command2]… ]…
[Else
  command1
  [command2]… ]…
End

DESCRIPTION

The If… control structure executes the list of commands following the first true (nonzero) expression. Note that null strings evaluate to zero. Although several expressions may be true, no more than one set of commands executes.

Note that the command's structure allows you to specify any number of Else If clauses and does not require a final Else clause; however, the following rules apply:

Return characters (as shown on the syntax line above) or semicolons must appear at the end of each line.

The pipe specification (|), conditional command terminators (&& and ||), and any input and output specifications (<, >, >>, ≥, ≥≥, ∑, and ∑∑) must appear following the End statement. They apply to all of the commands in the list.

IMPORTANT
Unlike standard C expression evaluation, the MPW shell evaluates each expression even if the first expression is true. To emulate C compiler behavior, put the Else clause inside a Begin…End construct. •

INPUT

None

OUTPUT

None

STATUS

If… can return the following status codes:

0

no errors or none of the lists of commands executed

-1

invalid expression

n

status code returned by the last command executed

PARAMETERS

command1 [command2]…

A list of one or more commands.

expression

A Boolean statement, MPW Shell variable, or string literal that can be evaluated to a 0 or nonzero value.

OPTIONS

None

EXAMPLES

The following If… control structure produces an audible indication of the success or failure of the command that came before it in the code.

If {Status} == 0
  Beep 1a,25,200
Else
  Beep -3a,25,200
End

In this script, the If… control structure closes all the open windows except the active window and the Worksheet window.

For window in `Windows`
  If "{window}"!="{Worksheet}" AND "{window}"!="{Active}"
  Close "{window}"
  End
End

Using the suffix of a file to determine whether it is written in C or C++, this script automatically compiles the file with the appropriate compiler.

If "{1}" =~ /≈.c/
  MrC {PPCCOptions} "{1}"
Else If "{1}" =~ /≈.cp/
  MrCpp {PPCCPlusOptions} "{1}"
End

If you save this script as a file named Compile, you can compile either a C or C++ file with the command

Compile filename

SEE ALSO

Evaluate

 
 


Last Updated July 2000