Your loop is almost right; however you forgot to initialize i=1 before entering the while loop, and the do/done keywords
質問
Convert the for-loop in the following script to a while-loop.
echo "Enter a number"
read n
count=0
for((i=1; i <= n; i++))
do
echo "Enter a number"
read a
if((a > 0))
then
count=$((count+1))
fi
done
echo "You entered $count positive number(s)"
my try:
while (i<=n)
echo "Enter a number"
read a
if ((a>0))
then
count=$((count+1))
i++
i dont know if i fully understand while and for loops. Thanks for your help ^_^
解決
所属していません StackOverflow