There's nothing wrong with your code because it clearly runs and does what is asked of it. It's possible there's a problem with your approach and you've had suggestions on alternative means of achieving similar results but since we don't know what the intended purpose is nobody's going to be able to give you a best method.…
This could have been me writing that. But in this case knowing how to code it is not essential for my life. So this quote - as accurate as it is - cannot be applied.