shell - 循环的2种方式

shell - 循环的2种方式

0, 题目描述

以打印0-50以内7的倍数为列

1, for循环

1.1 常规for循环

#!/bin/bash
for((i=0; i<50; i+=7))
do
    echo $i
done

1.2, for in 循环

#!/bin/bash
for i in {
    
    0..500..7}
do
    echo $i
done

# 说明(应该能看懂,所以无需多说,知道怎样用就OK了)

2, while循环

while 循环有两种条件表达方式,

  1. [ $a -lt $b ]
  2. ((a<b))

2.1, []型

#!/bin/bash

number=0

while [ $number -lt 500 ]
do
    echo $number
    number=$((number+7))
done

2.2, (())型

#!/bin/bash
number=0

while ((number<500))
do
    echo $number
    number=$((number+7))
    
done

3,shell 详细说明请查看shell学习

猜你喜欢

转载自blog.csdn.net/qq_44861043/article/details/117540097
今日推荐