Thread: I think I need some notation explained :( (if statements)

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    30

    I think I need some notation explained :( (if statements)

    I've gotten really confused about this... Below is a simple program I was messing with trying to fix my problem. ...Which I guess is in the if statements. The first "if" is fine...it prints out the first 10 numbers if the array. I want the second if to print out the second set of 10 numbers, but it prints out the first 20 instead...
    The third is fine now, but at first I had
    if(i<=20, i<30); which gave the same problem as with the second if - all 30 numbers were printed out instead of the third set of 10. Why is that different than
    if(i<30, i>=20), which works?

    Thanks.

    Code:
    #include <stdio.h>
    
    main()
    {
          int i;
          double array[30];
          
          for(i=0; i<30; i++){
                   array[i]=i;
                   }
                   
          for (i=0; i<30; i++) {
              if(i<10){
                       printf("111 %e\n", array[i]);
                       }
              if(i>=10, i<20){
                        printf("222  %e\n", array[i]);
                        }
              if(i<30, i>=20){
                             printf("333   %e\n", array[i]);
                             }
                             }
              getchar();
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Comma does not mean "and". "&&" means "and".

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    30
    Ack, I was thinking the comma was the problem, but then....oh...so the last on works just because of the i>=20. I get it now... :S
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression: Convert infix notation to postfix notation.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 02-27-2010, 07:44 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  4. CamelCase VS Hungarian notation, which is better?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2007, 09:31 PM
  5. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM