查看: 1161|回复: 2
收起左侧

[已解决] [Bash] 怎么让这个循环反着来

[复制链接]
kxmp
发表于 2018-6-28 22:20:23 | 显示全部楼层 |阅读模式
本帖最后由 kxmp 于 2018-6-30 18:39 编辑
#!/bin/bash

# nested-loop.sh: Nested "for" loops.

outer=1 # Set outer loop counter.

# Beginning of outer loop.
for ((a = 0; a<5; a++));
do
echo "Pass $outer in outer loop."
echo "---------------------"
inner=1 # Reset inner loop counter.

# ===============================================
# Beginning of inner loop.
for ((b = 0; b < 4; b++));
do
echo "Pass $inner in inner loop."
let "inner+=1" # Increment inner loop counter.
done
# End of inner loop.
# ===============================================

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

exit 0

Pass 1 in outer loop.---------------------Pass 1 in inner loop.Pass 2 in inner loop.Pass 3 in inner loop.Pass 4 in inner loop.Pass 2 in outer loop.---------------------Pass 1 in inner loop.Pass 2 in inner loop.Pass 3 in inner loop.Pass 4 in inner loop.Pass 3 in outer loop.---------------------Pass 1 in inner loop.Pass 2 in inner loop.Pass 3 in inner loop.Pass 4 in inner loop.Pass 4 in outer loop.---------------------Pass 1 in inner loop.Pass 2 in inner loop.Pass 3 in inner loop.Pass 4 in inner loop.Pass 5 in outer loop.---------------------Pass 1 in inner loop.Pass 2 in inner loop.Pass 3 in inner loop.Pass 4 in inner loop.


我怎么让他变成
Pass 1 in inner loop.Pass 2 in inner loop.Pass 3 in inner loop.Pass 4 in inner loop.
Pass 1 in outer loop.---------------------
imba-tjd
发表于 2018-6-30 18:00:02 | 显示全部楼层
你把外层循环的那句话放到里层结束之后不就好了……

评分

参与人数 1人气 +1 收起 理由
kxmp + 1 我的天哪...

查看全部评分

kxmp
 楼主| 发表于 2018-6-30 18:38:56 | 显示全部楼层
im-t 发表于 2018-6-30 18:00
你把外层循环的那句话放到里层结束之后不就好了……

我怎么没想到呢
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

手机版|杀毒软件|软件论坛| 卡饭论坛

Copyright © KaFan  KaFan.cn All Rights Reserved.

Powered by Discuz! X3.4( 沪ICP备2020031077号-2 ) GMT+8, 2024-11-25 17:42 , Processed in 0.135366 second(s), 17 queries .

卡饭网所发布的一切软件、样本、工具、文章等仅限用于学习和研究,不得将上述内容用于商业或者其他非法用途,否则产生的一切后果自负,本站信息来自网络,版权争议问题与本站无关,您必须在下载后的24小时之内从您的电脑中彻底删除上述信息,如有问题请通过邮件与我们联系。

快速回复 客服 返回顶部 返回列表