About the selection of odd and even numbers through *IF and *DO loop

    • Shekhar

      Dear Community,

      I have been practicing a thermal modelling routine in APDL.

      The modelling includes a repetition of a certain set of commands and scalar parameters in a cycle. I got it through the *DO and *IF commands. However, the code is getting extremely lengthy and time taking (for compilation) to set *IF command for every *DO parameter value (Like *DO is running from 1 to 100). But, in actuality the scalar parameters on change for the even and odd values of the *DO parameter.

      The code I want goes like this (but it is not working)




      X = 1


      X = 2




      If anybody knows how to set this working, please help

    • Daniel Shaw
      Ansys Employee
      There are probably multiple approaches that will work. One approach might be to use the MOD(x,y) function. to find the remainder. Something like:
      x1 = mod(ii,2) ! place immediately after *DO command
      If ii is an even number; then x1 would be equal to zero
      If ii is an odd number, then x1 would be equal to 1
      You can then use x1 in the *IF statements
Viewing 1 reply thread
  • You must be logged in to reply to this topic.