# Thread: broken logic

1. ## 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?

2. 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

3. 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?

4. >>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. || 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

Popular pages Recent additions