Chess board loop logic

need help for chess board loop logic.