Loop semantics: FOR C := A TO B DO ...

Mark William Hopkins markh at csd4.milw.wisc.edu
Sat Feb 4 04:01:11 AEST 1989


This problem was recently posed:

    Find a suitable translation in C for

    a, b, c: CHAR
    ...
    FOR c := a TO b DO <Body>

that correctly accounts for c's remaining inside its subrange 0..127 or
0..255 or whatever.  The answer is this:

	      for (c = a; c < b; c++) <Body>
	      if (c = b) <Body>

Of course, if you want to avoid duplication, you can go something like this:

	      for (c = a; c <= b; if (c < b) c++) <Body>



More information about the Comp.lang.c mailing list