[R] Beginner problem - using mod function to print odd numbers
    Stefan Evert 
    @te|@nML @end|ng |rom co||oc@t|on@@de
       
    Sat Jun  5 09:51:20 CEST 2021
    
    
  
> 
> I don't understand. -- 
> 
> 7%%2=1
> 9%%2=1
> 11%%2=1
> 
> What aren't these numbers printing ? 
> 
> num<-0
> for (i in 1:100){
>  num<-num+i
> if (num%%2 != 0) 
>  print(num)
> }
Your code tests the numbers
	1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, …
and correctly prints the odd ones among them.
But I suppose that's not what you wanted to do?
    
    
More information about the R-help
mailing list