從內層起,if 與下面最靠近的else 配對。
基本結構:
if () { }; else { };
要注意 花括號處若是單個語句,花括號可能略去,例如變成:
if () 單句 ; else { };
if () { }; else 單句 ;
if () 單句 ; else 單句 ;
你的程式是:
if (weight < 100 && height > 64)
{ if (height >= 72) printf ("you are very tall for your weight \n");
else printf ("you are tall ofr your weight \n"); }
else { if (weight > 300 && height < 48)
printf ("you are quite short for your weight \n");
else printf ("your weight is ideal \n"); };
從內層起,if 與下面最靠近的else 配對。
基本結構:
if () { }; else { };
要注意 花括號處若是單個語句,花括號可能略去,例如變成:
if () 單句 ; else { };
if () { }; else 單句 ;
if () 單句 ; else 單句 ;
你的程式是:
if (weight < 100 && height > 64)
{ if (height >= 72) printf ("you are very tall for your weight \n");
else printf ("you are tall ofr your weight \n"); }
else { if (weight > 300 && height < 48)
printf ("you are quite short for your weight \n");
else printf ("your weight is ideal \n"); };