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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Looping and Skipping
You are viewing a single comment's thread. Return to all comments →
Three things :
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 offor i in {1..100}
to get increment of 2.