mod m will help in traversing the blocks from starting block after we reach the end .
j = ( j + 1 ) % m ; } } document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( i + 1 + Array ( 20 ) . fill ( ' \xa0 ' ) . join ( ' ' ) + processSize [ i ] + Array ( 20 ) . fill ( ' \xa0 ' ) . join ( ' ' ) ) ; if ( allocation [ i ] != - 1 ) { document . write ( allocation [ i ] + 1 ) ; } else { document . write ( " " ) ; } document . write ( " " ) ; } }