I'm trying to use a modulo in my for loop in asymptote, however it does not compile. I have a syntax error on the modulo line. Without the modulo, it works just fine.

   for (int i=0; i<4; ++i) {
                if (i%2==0){
                    do stuff
                    do stuff

Could you please tell me how to write in correctly in Asymptote?

1 Answer 1


Put the \ before the percent sign

if (i\%2==0){
  • 4
    That should not be necessary. I'm wondering what the setup is where this makes a difference. Apr 23, 2020 at 16:26
  • 1
    I'm experiencing the same issue as TexShop is interpreting % as beginning a comment rather than being the modulo operator within Asymptote. For me, \% did not solve the issue.
    – Ari Gass
    Mar 3, 2021 at 22:22
  • @Ari Gass Can you share your code because it is difficult to interpret the cause of the error.
    – Moody
    Mar 5, 2021 at 4:34
  • My code is in the comment below. Sorry if the preamble is really messy. I tend to cut/paste so I don't accidentally leave something out that I might need.
    – Ari Gass
    Mar 8, 2021 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.