basic solution using for loop