Janis Papanagnou

2018-08-12 07:47:18 UTC

First a legacy question; I wonder what the difference in these [NH-343]

cases is:

trouble = in_trouble(); /* what's your worst difficulty? */

...

case 4: do fix_worst_trouble(trouble);

while ((trouble = in_trouble()) != 0);

break;

case 3: fix_worst_trouble(trouble);

case 2: while ((trouble = in_trouble()) > 0)

fix_worst_trouble(trouble);

break;

Case 4 seems to fix one trouble and continues while there is one.

Case 3 seems to fix one trouble and falls through into the case

where it fixes more troubles while there are any.

Case 2 seems to fix troubles while there are any.

It seems these cases do actually all the same. (This was NH-343 code.)

(It would make sense if one would replace 'while' by 'if' in case 2 to

fix only one trouble.) Or what am I missing?

In NH-360 only the case 2 is implemented slightly different:

case 2:

/* arbitrary number of tries */

while ((trouble = in_trouble()) > 0 && (++tryct < 10))

fix_worst_trouble(trouble);

break;

Here there's a count for maximum number of tries added, so that in

case 3 a maximum of 10 and in case 2 a maximum of 9 troubles is fixed.

Not much of variety either for cases 2, 3, and, 4, given that it's

rarely to expect that one has more than 9 troubles.

Janis, puzzled

cases is:

trouble = in_trouble(); /* what's your worst difficulty? */

...

case 4: do fix_worst_trouble(trouble);

while ((trouble = in_trouble()) != 0);

break;

case 3: fix_worst_trouble(trouble);

case 2: while ((trouble = in_trouble()) > 0)

fix_worst_trouble(trouble);

break;

Case 4 seems to fix one trouble and continues while there is one.

Case 3 seems to fix one trouble and falls through into the case

where it fixes more troubles while there are any.

Case 2 seems to fix troubles while there are any.

It seems these cases do actually all the same. (This was NH-343 code.)

(It would make sense if one would replace 'while' by 'if' in case 2 to

fix only one trouble.) Or what am I missing?

In NH-360 only the case 2 is implemented slightly different:

case 2:

/* arbitrary number of tries */

while ((trouble = in_trouble()) > 0 && (++tryct < 10))

fix_worst_trouble(trouble);

break;

Here there's a count for maximum number of tries added, so that in

case 3 a maximum of 10 and in case 2 a maximum of 9 troubles is fixed.

Not much of variety either for cases 2, 3, and, 4, given that it's

rarely to expect that one has more than 9 troubles.

Janis, puzzled