if.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:2k
- '"
- '" Copyright (c) 1993 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: if.n,v 1.3.18.1 2004/10/27 12:52:40 dkf Exp $
- '"
- .so man.macros
- .TH if n "" Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- if - Execute scripts conditionally
- .SH SYNOPSIS
- fBif fIexpr1 fR?fBthenfR? fIbody1 fBelseif fIexpr2 fR?fBthenfR? fIbody2fR fBelseiffR ... ?fBelsefR? ?fIbodyNfR?
- .BE
- .SH DESCRIPTION
- .PP
- The fIiffR command evaluates fIexpr1fR as an expression (in the
- same way that fBexprfR evaluates its argument). The value of the
- expression must be a boolean
- (a numeric value, where 0 is false and
- anything is true, or a string value such as fBtruefR or fByesfR
- for true and fBfalsefR or fBnofR for false);
- if it is true then fIbody1fR is executed by passing it to the
- Tcl interpreter.
- Otherwise fIexpr2fR is evaluated as an expression and if it is true
- then fBbody2fR is executed, and so on.
- If none of the expressions evaluates to true then fIbodyNfR is
- executed.
- The fBthenfR and fBelsefR arguments are optional
- ``noise words'' to make the command easier to read.
- There may be any number of fBelseiffR clauses, including zero.
- fIBodyNfR may also be omitted as long as fBelsefR is omitted too.
- The return value from the command is the result of the body script
- that was executed, or an empty string
- if none of the expressions was non-zero and there was no fIbodyNfR.
- .SH EXAMPLES
- A simple conditional:
- .CS
- fBiffR {$vbl == 1} { puts "vbl is one" }
- .CE
- .PP
- With an fBelsefR-clause:
- .CS
- fBiffR {$vbl == 1} {
- puts "vbl is one"
- } fBelsefR {
- puts "vbl is not one"
- }
- .CE
- .PP
- With an fBelseiffR-clause too:
- .CS
- fBiffR {$vbl == 1} {
- puts "vbl is one"
- } fBelseiffR {$vbl == 2} {
- puts "vbl is two"
- } fBelsefR {
- puts "vbl is not one or two"
- }
- .CE
- .PP
- Remember, expressions can be multi-line, but in that case it can be a
- good idea to use the optional fBthenfR keyword for clarity:
- .CS
- fBiffR {
- $vbl == 1 || $vbl == 2 || $vbl == 3
- } fBthenfR {
- puts "vbl is one, two or three"
- }
- .CE
- .SH "SEE ALSO"
- expr(n), for(n), foreach(n)
- .SH KEYWORDS
- boolean, conditional, else, false, if, true