loop imrovement to resemble php syntax