Change db loops style from for to while