Thread: broken logic

  1. #1
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435

    broken logic

    I've messed up bigtime here somewhere. First of all, here's the code:

    Code:
    if(p->next->t.gid == PARSE_GLUE)
    {
    	printf("I am rubber, you are glue\n");
    
    	if(p->next->t.tid == OPEN_BRACKET)
    		printf("indeed, it is magical\n");
    	else if(p->next->t.tid == CLOSE_BRACKET)
    		printf("AAAAGGGGHH MONKEY CRAP\n");
    };
    
    printf("no it is not\n");
    
    while(p->next->t.gid != PARSE_GLUE && p->next->t.tid != CLOSE_BRACKET)
    {
    	printf("THE ANSWER IS YES\n");
    the output:

    I am rubber, you are glue
    indeed, it is magical
    not it is not

    - I have to ask, where have I screwed up?
    while the first condition of the while loop is false, isn't the second true so both are ok? I mean, if one moment p->next->t.tid == OPEN_BRACKET and then the next it equals CLOSE_BRACKET, then what are things coming too? I have similar while loops in other places that behave perfectly... so what have I done wrong?
    .sect signature

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    Code:
    if(p->next->t.gid == PARSE_GLUE)
    {
    	printf("I am rubber, you are glue\n");
    
    	if(p->next->t.tid == OPEN_BRACKET)
    		printf("indeed, it is magical\n");
    	else if(p->next->t.tid == CLOSE_BRACKET)
    		printf("AAAAGGGGHH MONKEY CRAP\n");
    };  /* why the termination here ; */
    
    printf("no it is not\n"); 
    
    while(p->next->t.gid != PARSE_GLUE && p->next->t.tid != CLOSE_BRACKET)
    {
    	printf("THE ANSWER IS YES\n");
    the use of ";" after close brace could be your problem
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    No. Semicolons after brace closings are simply a matter of style, shouldn't cause any trouble (unless it's an if ... else 0_o)

    anybody else?
    .sect signature

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>while the first condition of the while loop is false, isn't the second true so both are ok?

    Not if you are using '&&'....for that then both conditions must be true..........use '||' .......then either casn be true

  5. #5
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    || won't work because of the possibilities of clashing tokens, but thank you very much. I had another loop...

    Code:
    while(p->next->t.gid != PARSE_GLUE && p->next->t.tid != SEMICOLON)
    that worked fine, but you've made me realize that it was never fed any tokens with PARSE_GLUE as the gid. thank you, now I need to find a solution !@:$

    good day to you sirs
    .sect signature

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 01:05 PM
  2. Logic
    By LordBronz in forum C++ Programming
    Replies: 6
    Last Post: 05-23-2006, 05:41 PM
  3. Actors, cues, event based logic.
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-27-2006, 10:58 PM
  4. Circular Logic
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-15-2001, 08:10 PM