Logan Lee wrote:
Sun, 23 Dec 2007 10:34:54 +0000에, Logan Lee 썼습니다:
>Hi. What is the difference between
if {}
if {}
if {}
if else {}
?
I meant else if and not if else.
Let's write something that more closely resembles legal C code:
A:
if (condition1) { statements1;}
if (condition2) { statements2;}
B:
if(condition1) {statement1;}
else if(condition2) {statements2;}
To keep this simple, I'm using statements1 and statments to each
represent a series of statements that doesn't include a return
statement, and doesn't directly or indirectly call exit(), abort(), or
longjmp().
The difference between A: and B: is that in A:, condition2 is evaluated
regardless of what condition1 is; in B:, condition2 is evaluated only if
condition1 compares equal to 0. In A:, statements2 are always executed
if condition2 does not compare equal to 0, regardless of what condition1
is. In B:, statements2 are only executed if condition1 compares equal to
0 and condition two does not compare equal to 0.