lets take an exemple:
N= 5 , M= 2
i = 0 if( 0 modulo 2) the condition is true so print 0
i = 1 if( 1 modulo 2) the condition is false so print the approximate previous number which is modulo 2 ,thats 0 then print 0
i = 2 if( 2 modulo 2) the condition is true so print 2
i = 3 if( 3 modulo 2) the condition is false so print the approximate previous number which is modulo 2 ,thats 2 then print 2