Chinaunix首页 | 论坛 | 博客
  • 博客访问: 343218
  • 博文数量: 115
  • 博客积分: 1019
  • 博客等级: 准尉
  • 技术积分: 1104
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-22 15:02
个人简介

别想万里,要把一只脚放到另一脚的前边

文章分类

全部博文(115)

文章存档

2018年(1)

2015年(2)

2014年(31)

2013年(38)

2012年(43)

我的朋友

分类: LINUX

2013-12-26 15:37:31


点击(此处)折叠或打开

  1. 1.2. Nested Loops

  2. A nested loop is a loop within a loop, an inner loop within the body of an outer one. How this works is that the first pass of the outer loop triggers the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again. This repeats until the outer loop finishes. Of course, a break within either the inner or outer loop would interrupt this process.

  3. Example 11-19. Nested Loop

  4. #!/bin/bash
  5. # nested-loop.sh: Nested "for" loops.

  6. outer=1 # Set outer loop counter.

  7. # Beginning of outer loop.
  8. for a in 1 2 3 4 5
  9. do
  10.   echo "Pass $outer in outer loop."
  11.   echo "---------------------"
  12.   inner=1 # Reset inner loop counter.

  13.   # ===============================================
  14.   # Beginning of inner loop.
  15.   for b in 1 2 3 4 5
  16.   do
  17.     echo "Pass $inner in inner loop."
  18.     let "inner+=1" # Increment inner loop counter.
  19.   done
  20.   # End of inner loop.
  21.   # ===============================================

  22.   let "outer+=1" # Increment outer loop counter.
  23.   echo # Space between output blocks in pass of outer loop.
  24. done
  25. # End of outer loop.

  26. exit 0

阅读(403) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

wuxiaobo_20092013-12-26 15:45:49

嵌套 for 基础从头做起