What are the differences between the following if loops???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deva21
    New Member
    • Feb 2014
    • 3

    What are the differences between the following if loops???

    What is the difference between
    -if(a%2==0&&a%3= =0)
    -if(!(a%2==0&&a% 3==0) and
    -if(!(a%2!=0&&a% 3!=0)

    Please explain
  • Deva21
    New Member
    • Feb 2014
    • 3

    #2
    I forgot to ask this. Also give me the difference between if(!(a%2==0&&b% 3==0)) and if(a%2!=0&&b%3! =0)

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Do you understand what a%2==0 means?

      Let's start there.

      Comment

      • Deva21
        New Member
        • Feb 2014
        • 3

        #4
        :( Yea,it is modulo division, and it gives the remainder when divided.. I checked the boolean values for all 3 and got their difference. Anyway Thank You.

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          The % operator is commonly called the "modulo" operator, however it can be argued that it is more mathematically accurate to call it the "remainder" argument. Regardless, I think @weaknessforcat s was asking you what it means when a%2 is equal to 0. What does that tell you about a and 2?

          By the way, when considering a%b, it is helpful if you are certain that both a and b are greater than 0. The results are counter-intuitive for negative operands; Zero is not allowed for b; and 0 % b is 0 for all nonzero b. the modulo and remainder arguments give the same results for positive operands, but results differ for negative operands. - but this is a pedantic distinction of no relevance to your original question.
          Last edited by donbock; Mar 2 '14, 04:39 AM. Reason: Added pedantic reference to modulo vs remainder.

          Comment

          Working...