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)