foreach

foreach(3tcl)                Tcl Built-In Commands               foreach(3tcl)



______________________________________________________________________________

NAME
       foreach - å¨ä¸ä¸ªæå¤ä¸ªå表çææåç´ ä¸éå¤

æ»è§ SYNOPSIS
       foreach varname list body
       foreach varlist1 list1 ?varlist2 list2 ...? body
_________________________________________________________________


æè¿° DESCRIPTION
       foreach
       å½ä»¤å®ç°ä¸ä¸ªå¾ªç¯ï¼å¨è¿é循ç¯åéä»ä¸ä¸ªæå¤ä¸ªå表æ¥åå¼ãå¨æç®åçæåµä¸ï¼è¿éæä¸ä¸ªå¾ªç¯åé
       varname  ï¼åä¸ä¸ªå表 listï¼å®æ¯è¦èµç» varname  çå¼çä¸ä¸ªå表ãbody
       åæ°æ¯ä¸ä¸ª Tcl èæ¬ãå¯¹äº list   çæ¯ä¸ªåç´ (æä»æåå°æåç次åº)ï¼foreach
       æè¿ä¸ªåç´ çå容èµç» varnameï¼å¦åä½¿ç¨ lindex
       å½ä»¤æååç´ ä¸æ ·ï¼æ¥çè°ç¨ Tcl 解éå¨æ¥æ§è¡ bodyã

       å¨ä¸è¬çæåµä¸ï¼è¿éå¯ä»¥æå¤äºä¸ä¸ªçå¼å表(ä¾å¦ï¼list1å
       list2)ï¼å¹¶ä¸æ¯ä¸ªå¼å表å¯ä»¥ä¸ä¸ä¸ªå¾ªç¯åéçå表ç¸å³èã(ä¾å¦ï¼varlist1 å
       varlist2)ã å¨å¾ªç¯çæ¯æ¬¡éå¤æé´æ¯ä¸ª varlist ä¸çåé被èµä¸ç¸åºçlist ä¸‐
       çè¿ç»çå¼ãå¨æ¯ 个list ä¸‐
       çå¼æä»æåå°æåç次åºè¢«ä½¿ç¨ï¼å¹¶ä¸æ¯ä¸ªå¼è¢«åç¡®ç使ç¨ä¸æ¬¡ã循ç¯éå¤çæ»æ°è¶³å¤ç大æ¥ç¨åææå表çææçå¼ãå¦æä¸ä¸ªå¼çå表ä¸åå«è¶³å¤åç´ ï¼ä¾ç»æ¯æ¬¡éå¤ä¸‐
       çæ¯ä¸ªå¾ªç¯åéï¼åç»éæ¼çåç´ ä½¿ç¨ç©ºå¼ã

       break  å continue  è¯å¥å¯ä»¥å¨ body ä¸è°ç¨ï¼ä¸å¨ for å½ä»¤ä¸‐
       æç¸åçææãForeach  è¿åä¸ä¸ªç©ºä¸²ã

èä¾ EXAMPLES
       ä¸é¢ç循ç¯ä½¿ç¨ i å j ä½ä¸ºå¾ªç¯åéå¨ä¸ä¸ªåä¸çå表çä¸å¯¹åç´ ä¸éå¤ã set 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.

       ä¸ä¸ä¸ªå¾ªç¯ä½¿ç¨ i å j å¨ä¸¤ä¸ªå¹¶è¡çå表ä¸éå¤ã set 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.

       å¨ä¸é¢ä¾åä¸ç»åäºä¸¤ç§å½¢å¼ã set 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.


åè§ SEE ALSO
       for(n), while(n), break(n), continue(n)


å³é®å KEYWORDS
       foreach, iteration, list, looping


[ä¸æçç»´æ¤äºº]
       å¯èé士

[ä¸æçææ°æ´æ°]
       2001/08/05

ãä¸å½ Linux 论å man æå页翻è¯è®¡åã:
       http://cmpp.linuxforum.net

è·
       æ¬é¡µé¢ä¸æçç±ä¸æ man æå页计åæä¾ã
       ä¸æ man æå页计åï¼https://github.com/man-pages-zh/manpages-zh



Tcl                                                              foreach(3tcl)