|
我用C shell写了一个测试脚本,内容如附图
1 #!/bin/csh
2 #
3 foreach i (1 2 3 4)
4 echo "when i=$i,enter the test"
5 if($i < 3)then
6 echo "in outer-select then"
7 if($i == 1)then
8 echo "in inner-select1 then"
9 else
10 echo "in inner-select1 else"
11 endif
12 else
13 echo "in outer-select else"
14 if($i == 3)then
15 echo "in inner-select2 then"
16 else
17 echo "in inner-select2 else"
18 endif
19 endif
20 end
运行结果为
Newton% cycletest
when i=1,enter the test
in outer-select then
in inner-select1 then
when i=2,enter the test
in outer-select then
in inner-select1 else
when i=3,enter the test
in inner-select1 else
when i=4,enter the test
in inner-select1 else
Newton%
很显然,当i=3时,应显示in outer-selection else和in inner-select2 then
当i=4时,应显示in outer-selection else和in inner-select2 else
但是,很明显的,系统把第9行的else看做是属于外层选择结构的.
这样就不能用到if-else-endif多重选择,只能用外层if-else-endif包内层switch-case来实现
请问大家是怎么处理这种问题的,用什么来实现多重循环呢? |
|