🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4623

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

#4623
From: Mark William Hopkins
Date: Fri, 03 Feb 1989 18:01
17 lines
900 bytes
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>
Technical Details
Message-ID: <763@csd4.milw.wisc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!markh

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!markh
From: markh@csd4.milw.wisc.edu (Mark William Hopkins)
Newsgroups: comp.lang.modula2,comp.lang.c
Subject: Loop semantics: FOR C := A TO B DO ...
Message-ID: <763@csd4.milw.wisc.edu>
Date: 3 Feb 89 18:01:11 GMT
Sender: news@csd4.milw.wisc.edu
Reply-To: markh@csd4.milw.wisc.edu (Mark William Hopkins)
Organization: University of Wisconsin-Milwaukee
Lines: 17