I'm no expert, but I honestly thought I understood
if
and
else
OK... but I'm not sure now :~
So, just to make absolutely sure, if you have
int a = 0;
int b = 1;
CString strOutput;
if(a == 0)
{
strOutput = "I am a boy.";
}
else if(b == 1)
{
strOutput = "I am a girl.";
}
what does
strOutput
say?
I thought it'd be "I am a boy.", but I was debugging through some code when it said "I am a boy." then "I am a girl.", i.e. executed both branches.
Admittedly, I was making a mess of memory access all over the place, so it could have been that, but please, some one tell me, should this piece of code execute all paths, or just one? And have I got the number of brackets right? (The compiler should have spotted that, of course, but hey...)
As an aside, part of the confusion is that my preferred tool that is Matlab distinguishes between
if
-
else
and
if
-
elseif
.