使用for循环打印1到N. [英] Printing 1 to N with for loop

查看:159
本文介绍了使用for循环打印1到N.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须取N的整数值并在ubuntu linux shell中使用for循环打印从1到N的系列。



我找不到任何东西谷歌适用于我的系统。



我迄今为止尝试过的失败是:



for ((c = 1; c <= 5; c ++))

do

echo$ c

完成







n = 5

for val in {1 .. $ n}

do

echo$ val

完成



提前致谢。

解决方案

c

完成







n = 5

for val in {1 ..


n}

do

echo


val

完成



提前致谢

I have to take an integer value of N and using a for loop in a ubuntu linux shell print a series from 1 to N.

I cannot find anything on google which works for my system.

What I have tried so far unsuccessfully is:

for (( c=1; c<=5; c++ ))
do
echo "$c"
done

and

n=5
for val in { 1..$n }
do
echo "$val"
done

Thanks in advance.

解决方案

c"
done

and

n=5
for val in { 1..


n }
do
echo "


val"
done

Thanks in advance.


这篇关于使用for循环打印1到N.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆