Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Issues with array, strlen, etc |
| Date | 2015-09-10 07:34 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <msrpot$1rm$1@dont-email.me> (permalink) |
| References | <1866812f-e415-44b4-8127-8e21c4a13653@googlegroups.com> <1e5f8717-847a-451c-8e50-7e87115ead51@googlegroups.com> <lnlhcgsxs9.fsf@kst-u.example.com> <061a430f-e33f-4661-a8c5-506bf106c590@googlegroups.com> <MjbIx.485700$8E7.431470@fx29.am4> |
On 9/10/2015 4:38 AM, Richard Heathfield wrote:
> [...]
> In this loop:
>
> for(x; y; z)
> {
> the_loop_body;
> }
>
> x is only executed once, at the beginning. y, z, and the_loop_body are
> executed once *per loop iteration*. [...]
Richard isn't wrong very often, but he's wrong this time.
x is executed once; Richard is right.
y is executed either (1) the same number of times as
the_loop_body or (2) one more time than the_loop_body.
z is executed either (2) the same number of times as
the_loop_body or (1) one fewer time than the_loop_body.
Case (2) might be considered the "normal" case, when
the loop terminates by the action of the `for' part alone.
In this case, y precedes and z follows each the_loop_body
execution, and y executes one additional time (when it
evaluates to false and stops the loop).
Case (1) holds when the_loop_body itself terminates the
loop, by executing a `break' or `return' or `goto' or the
like. In this case, y precedes each the_loop_body execution
and z follows each one except the last.
Caveat: All the above presumes that none of x,y,z, or
the_loop_body invokes undefined behavior, in which case
there's no telling what might happen.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Issues with array, strlen, etc Alla _ <modelling.data@gmail.com> - 2015-09-07 10:47 -0700
Re: Issues with array, strlen, etc James Kuyper <jameskuyper@verizon.net> - 2015-09-07 14:47 -0400
Re: Issues with array, strlen, etc bartekltg <bartekltg@gmail.com> - 2015-09-07 22:03 +0200
Re: Issues with array, strlen, etc Paul N <gw7rib@aol.com> - 2015-09-07 13:08 -0700
Re: Issues with array, strlen, etc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-07 22:55 +0100
Re: Issues with array, strlen, etc Rosario19 <Ros@invalid.invalid> - 2015-09-08 07:59 +0200
Re: Issues with array, strlen, etc Rosario19 <Ros@invalid.invalid> - 2015-09-08 08:05 +0200
Re: Issues with array, strlen, etc Barry Schwarz <schwarzb@dqel.com> - 2015-09-07 20:35 -0700
Re: Issues with array, strlen, etc Alla _ <modelling.data@gmail.com> - 2015-09-08 01:08 -0700
Re: Issues with array, strlen, etc Keith Thompson <kst-u@mib.org> - 2015-09-08 09:04 -0700
Re: Issues with array, strlen, etc Alla _ <modelling.data@gmail.com> - 2015-09-10 01:22 -0700
Re: Issues with array, strlen, etc Richard Heathfield <rjh@cpax.org.uk> - 2015-09-10 09:38 +0100
Re: Issues with array, strlen, etc Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-10 07:34 -0400
Re: Issues with array, strlen, etc David Brown <david.brown@hesbynett.no> - 2015-09-10 13:47 +0200
Re: Issues with array, strlen, etc Richard Heathfield <rjh@cpax.org.uk> - 2015-09-10 13:11 +0100
Re: Issues with array, strlen, etc Keith Thompson <kst-u@mib.org> - 2015-09-10 10:21 -0700
Re: Issues with array, strlen, etc Geoff <geoff@invalid.invalid> - 2015-09-10 10:42 -0700
Re: Issues with array, strlen, etc Alla _ <modelling.data@gmail.com> - 2015-09-08 01:11 -0700
Re: Issues with array, strlen, etc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-08 09:51 +0100
Re: Issues with array, strlen, etc Alla _ <modelling.data@gmail.com> - 2015-09-08 02:39 -0700
csiph-web