How do i use the loops for solving such problems?

here i am having trouble in understanding how to use loops for such problems