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


Groups > comp.lang.c > #5931

Re: (simple) condition within for loop

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: (simple) condition within for loop
Date 2011-06-13 11:08 +1200
Message-ID <95kv82FrhmU3@mid.individual.net> (permalink)
References <582385e0-5f22-49d2-9703-e8f591c9927b@y30g2000yqb.googlegroups.com>

Show all headers | View raw


On 06/13/11 10:58 AM, papoupapa wrote:
> Hi,
>
> The code below doesn't read the condition that says to stop when the
> entry is 0. A while loop might be more convenient....
>
>
> #include<stdio.h>
>
> #define CMAX 5
>
> int main(void)
> {
> 	int Numbers[CMAX] ;
> 	int nbr_in ;
> 	int i, j ;
>
> 	nbr_in = 1 ;
> 	j = 0 ;
> 	for (i = 0  ; (nbr_in != 0) || (i<  CMAX)  ;  i++, j++)

This will keep reading until nbr_in == 0 *AND* i >= CMAX!

You wanted && there (ant later), not ||

-- 
Ian Collins

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