The first row and column must be implemented with separate loops.