I know exactly how does a single modulus work. Does double modulus work the same? And assuming we have this pseudocode
j<-0
n<-10
for(j in 1:n)
{ if(!j%%2)
{
next
}
print(j)
}
What does the 'if' condition mean and what is the output of this code?
My solution is: If J is not divisible by 2 increase J, Otherwise, print J. And the overall code outputs even numbers from (1-10). Is this solution correct?
The %%
operators is, as far as I know, not "standard" enough to be able to use it unambiguously in pseudocode without accompanying explanation of what it is supposed to be.
This snippet appears to be R code though, and in R the %%
operator does mean remainder (with the sign of the divisor).
But since there is a !
(logical-not) too, the code will be printing odd numbers, since it's skipping the even numbers.