In reply to Saikat Sana:
You could help others help you by providing more information about the problem you are facing. - i.e. what errors you are getting and what you expected to work.
The only thing I can see wrong is your initial block needs to be moved inside the for loop.