⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foreach.n

📁 linux系统下的音频通信
💻 N
字号:
'\"'\" 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.'\" '\" SCCS: @(#) foreach.n 1.6 96/03/25 20:15:14'\" .so man.macros.TH foreach n "" Tcl "Tcl Built-In Commands".BS'\" Note:  do not modify the .SH NAME line immediately below!.SH NAMEforeach \- Iterate over all elements in one or more lists.SH SYNOPSIS\fBforeach \fIvarname list body\fR.br\fBforeach \fIvarlist1 list1\fR ?\fIvarlist2 list2 ...\fR? \fIbody\fR.BE.SH DESCRIPTION.PPThe \fBforeach\fR command implements a loop where the loopvariable(s) take on values from one or more lists.In the simplest case there is one loop variable, \fIvarname\fR,and one list, \fIlist\fR, that is a list of values to assign to \fIvarname\fR.The \fIbody\fR argument is a Tcl script.For each element of \fIlist\fR (in orderfrom first to last), \fBforeach\fR assigns the contents of theelement to \fIvarname\fR as if the \fBlindex\fR command had been usedto extract the element, then calls the Tcl interpreter to execute\fIbody\fR..PPIn the general case there can be more than one value list(e.g., \fIlist1\fR and \fIlist2\fR),and each value list can be associated with a list of loop variables(e.g., \fIvarlist1\fR and \fIvarlist2\fR).During each iteration of the loopthe variables of each \fIvarlist\fP are assignedconsecutive values from the corresponding \fIlist\fP.Values in each \fIlist\fP are used in order from first to last,and each value is used exactly once.The total number of loop iterations is large enough to useup all the values from all the value lists.If a value list does not contain enoughelements for each of its loop variables in each iteration,empty values are used for the missing elements..PPThe \fBbreak\fR and \fBcontinue\fR statements may beinvoked inside \fIbody\fR, with the same effect as in the \fBfor\fRcommand.  \fBForeach\fR returns an empty string..SH EXAMPLES.PPThe following loop uses i and j as loop variables to iterate overpairs of elements of a single list..DSset x {}foreach {i j} {a b c d e f} {    lappend x $j $i}# The value of x is "b a d c f e"# There are 3 iterations of the loop..DE.PPThe next loop uses i and j to iterate over two lists in parallel..DSset x {}foreach i {a b c} j {d e f g} {    lappend x $i $j}# The value of x is "a d b e c f {} g"# There are 4 iterations of the loop..DE.PPThe two forms are combined in the following example..DSset x {}foreach i {a b c} {j k} {d e f g} {    lappend x $i $j $k}# The value of x is "a d e b f g c {} {}"# There are 3 iterations of the loop..DE.SH KEYWORDSforeach, iteration, list, looping

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -