----- Original Message ---- >Or put another way, what if there was a outer IF not shown > above, and ELSE was meant to be part of it, not the IF shown. How would= you > then end the IF shown so that the ELSE would not be part of it? >=20 > For example: >=20 > if (outer_condition) > if (inner_condition) count=3D0; //TRUE case of outer IF > else > do_something(); //FALSE case of outer IF >From the link I gave you: "An else always matches the nearest previous unmatched if; braces may be us= ed to=20 override this when necessary, or for clarity." > How do you "end" the second IF so that the ELSE belongs to the first IF?= =20 It's not really a problem with the second IF but with your lack of understa= nding=20 of what constitutes the "true statement" of the first IF. > if what you're saying above is true, then the only way to do this is to = put=20 >the > second IF inside brackets? =20 Yes, that's exactly right. To get the behaviour you want you need this: if(outer_condition) { if(Inner_conditional) count =3D 0; } else do_someting(); > I suppose that's at least consistant, but just > asking for easily made mistakes. Not if you know what you are doing. :-) > Worse, what I wrote above would not be > interpreted as intended, but would be perfectly legal and not generate a= ny > compile error. Indeed, but who's fault is that ? You wrote valid C and that's really all = the=20 compiler can check for. If your C code doesn't do what you expected it to do then it's because you don't understand the C= =20 syntax and that's not the compiler's fault ! ;-) > This is why it seemed logical that the ";" would end the inner IF. It's not logical to an experienced C coder :-) > But if > what you're saying is true (I expect it is, as I said, I'm no C whiz), i= t's > hard to imagine what was going thru K&R's minds when they designed the > syntax. >=20 > This would be yet another reason to religiously use brackets in IF > statements. That's probably why I never bumped into this in real code. I often use extra brackets and my trick is to type all the brackets and=20 semicolons first, so that in your case above I would type this first: if() { if() ; } else { ; } Then I go back and fill in the statements and remove any unneeded pairs of= =20 brackets. Use of a consistent layout style also helps avoid problems. =20 PeterO --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .