SyntaxFix
Write A Post
Hire A Developer
Questions
Your piece of script works just great. Are you sure you are not assigning anything else before the if to "i"?
A common mistake is also not to leave a space after and before the square brackets.