What should be added to C

Kent Black kab at reed.UUCP
Thu Jun 12 03:22:05 AEST 1986


In article <779 at steinmetz.UUCP> davidsen at kbsvax.UUCP (Davidsen) writes:
>In article <1497 at mmintl.UUCP> franka at mmintl.UUCP (Frank Adams) writes:
>>In article <5498 at alice.uUCp> ark at alice.UUCP writes:
>>>Frank Adams says:
>>>> o An andif clause for if statements.
>>
>>You would write:
>>
>>  if (A) {
>>    X
>>  } andif (B) {
>>    Y
>>  } else {
>>    Z
>>  }
>>
>>This is equivalent to:
>>
>>   if (!(A)) goto _Z;
>>   X
>>   if (B) {
>>     Y
>>   } else {
>>_Z:
>>     Z
>>   }
>
>*you* might do that, but most people would nest the "if (B)" after the
>"if (A)".
>
>  if (A) {
>    X
>    if (B) {
>      Y
>    }
		/* if (!B) ??? */
>  } else {
>    Z
>  }
>

Yep, I was there among "most people"; unfortunately, it isn't the same code.
The original can be rewritten as:

    if (A)    {
        X;
        if (B)  Y;
        else    goto _Z;
    }
    else    {
_Z:		/* this deserves a comment! :-) */
            Z;
    }

Flow of control is to 'Z' on (!A) OR (!B).  If gotooz are anathema, flags
can be used, e.g.,

    aflag = bflag = FALSE;

    if (A)	{
        aflag = TRUE;
        X;
	if (B)
	    bflag = TRUE;
	    Y;
    } 
    if (aflag == FALSE || bflag == FALSE)	{
        Z;
    }

-----------------
My apologies to Bill Davidsen for not digging out my own posting, to
Frank Adams for not reading carefully and to the rest of the net.
-----------------

Kent Black	(...tektronix!reed!kab)



More information about the Comp.lang.c mailing list