We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

1) i = $((i+2)) will give an error because of extra space around "=".
It can be corrected to : i=$((i+2))

2) The above mentioned line i=$((i+2)) is actually unnecessary because the updated value of i is never used, and overwritten by for in next iteration. Hence, this line can be completely removed.

3) Use for i in {1..100..2} instead of for i in {1..100} to get increment of 2.

## Looping and Skipping

You are viewing a single comment's thread. Return to all comments →

Three things :

1)

`i = $((i+2))`

will give anerrorbecause of extra space around "=". It can be corrected to :`i=$((i+2))`

2) The above mentioned line

`i=$((i+2))`

is actually unnecessary because the updated value ofiis never used, and overwritten byforin next iteration. Hence, this line can be completely removed.3) Use

instead of`for i in {1..100..2}`

`for i in {1..100}`

to get increment of2.what if i want to increment inside the loop?

Then you can use

, also make sure to initialize`while [ $i -le 100 ]`

`i=1`

in this case.You can also use C like construct :

, but then again, this won't allow you to increment inside loop.`for (( i=1; i<=100; i+=2 ))`