Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #5947

Re: (simple) condition within for loop

From Nobody <nobody@nowhere.com>
Subject Re: (simple) condition within for loop
Date 2011-06-13 02:32 +0100
Message-Id <pan.2011.06.13.01.32.19.938000@nowhere.com>
Newsgroups comp.lang.c
References <582385e0-5f22-49d2-9703-e8f591c9927b@y30g2000yqb.googlegroups.com> <laiav6t16tk5vi9k9n96qs20qnqmrnn1kv@4ax.com> <95l0abFrhmU6@mid.individual.net>
Organization Zen Internet

Show all headers | View raw


On Mon, 13 Jun 2011 11:27:07 +1200, Ian Collins wrote:

>> Read your text about 'for' loops and the 'break' statement.
>> Test conditionals with 'if' as in "if (num_in == 0)".
>> Use the same technique for both loops.
> 
> Why?  What's wrong with testing more than one condition in a for loop 
> (assuming the logic is correct!)?

Nothing. Except that the loop condition determines whether the loop should
continue while if-break determines whether it should terminate. If you
know the termination condition, using it as such in an if-break may be
less error-prone than determining the equivalent loop condition (if
there even is such a condition, which may not be the termination test
isn't at the end of the loop body).

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

(simple) condition within for loop papoupapa <papoupapoug@gmail.com> - 2011-06-12 15:58 -0700
  Re: (simple) condition within for loop Ian Collins <ian-news@hotmail.com> - 2011-06-13 11:08 +1200
  Re: (simple) condition within for loop Geoff <geoff@invalid.invalid> - 2011-06-12 16:24 -0700
    Re: (simple) condition within for loop Ian Collins <ian-news@hotmail.com> - 2011-06-13 11:27 +1200
      Re: (simple) condition within for loop Geoff <geoff@invalid.invalid> - 2011-06-12 16:47 -0700
        Re: (simple) condition within for loop Ian Collins <ian-news@hotmail.com> - 2011-06-13 12:01 +1200
          Re: (simple) condition within for loop Geoff <geoff@invalid.invalid> - 2011-06-12 19:51 -0700
            Re: (simple) condition within for loop papoupapa <papoupapoug@gmail.com> - 2011-06-13 06:00 -0700
              Re: (simple) condition within for loop Willem <willem@toad.stack.nl> - 2011-06-13 14:39 +0000
              Re: (simple) condition within for loop "J. J. Farrell" <jjf@bcs.org.uk> - 2011-06-13 22:13 +0100
              Re: (simple) condition within for loop Geoff <geoff@invalid.invalid> - 2011-06-13 17:13 -0700
        Re: (simple) condition within for loop Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-14 15:58 -0700
      Re: (simple) condition within for loop Nobody <nobody@nowhere.com> - 2011-06-13 02:32 +0100
        Re: (simple) condition within for loop "Herbert Rosenau" <os2guy@pc-rosenau.de> - 2011-06-14 06:41 +0000

csiph-web