last LABEL last |
不是一個函數。last關鍵字立即使循環當前迭代,成為最後一個循環控製語句。冇有進一步的語句被執行,並結束循環。如果指定LABEL,然後它丟棄循環的識彆LABEL,而不是目前的封閉循環。
Nothing
試試下麵的例子:
#!/usr/bin/perl $count = 0; while( 1 ){ $count = $count + 1; if( $count > 4 ){ print "Going to exist out of the loop\n"; last; }else{ print "Count is $count\n"; } } print "Out of the loop\n"; It will produce foillowing result: #by www.gitbook.net Count is 1 Count is 2 Count is 3 Count is 4 Going to exist out of the loop Out of the loop