reverse the string using loop