[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: for ((i=0; i<3 && i!=1; i++))
From: |
Greg Wooledge |
Subject: |
Re: for ((i=0; i<3 && i!=1; i++)) |
Date: |
Mon, 12 Jan 2015 11:39:35 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, Jan 12, 2015 at 05:26:15PM +0800, l_j_f wrote:
> for ((idx=0; idx<3 && idx != current; idx++)); do
> echo $idx
> done
> # I think it should be
> 0
> 2
No, this is not a bug. The second expression in "for ((expr; expr; expr))"
tells bash when to terminate the entire for loop. So, the loop terminates
when idx == current.
If you just want to skip a single iteration when idx == current, do it
like this:
for ((idx=0; idx<3; idx++)); do
if ((idx == current)); then continue; fi
echo "$idx"
done