Em 29/12/2010 12:30, Olin Lathrop escreveu: > PETER ONION wrote: >>>> if(diff >=3D 0) >>>> byte =3D 0; >>>> else >>>> >>>> { >>>> byte =3D 8; >>>> diff =3D - diff; >>>> } >> The ";" just terminates the "if true statement". > But if a semicolon doesn't end the IF statement, what does end it > unambiguously? Or put another way, what if there was a outer IF not show= n > 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? Then the entire inner 'if' must be enclosed inside curly braces. if (outer_condition) { if (inner_condition) count=3D0; //TRUE case of outer IF } else do_something(); //FALSE case of outer IF > For example: > > if (outer_condition) > if (inner_condition) count=3D0; //TRUE case of outer IF > else > do_something(); //FALSE case of outer IF > > How do you "end" the second IF so that the ELSE belongs to the first IF? = If > what you're saying above is true, then the only way to do this is to put = the > second IF inside brackets? I suppose that's at least consistant, but jus= t > asking for easily made mistakes. Worse, what I wrote above would not be > interpreted as intended, but would be perfectly legal and not generate an= y > compile error. > > This is why it seemed logical that the ";" would end the inner IF. But i= f > what you're saying is true (I expect it is, as I said, I'm no C whiz), it= 's > hard to imagine what was going thru K&R's minds when they designed the > syntax. > > 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. > > > ******************************************************************** > Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products > (978) 742-9014. Gold level PIC consultants since 2000. __________________________________________________ Fale com seus amigos de gra=E7a com o novo Yahoo! Messenger=20 http://br.messenger.yahoo.com/=20 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .