Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6664
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: simple for loop i find not coherent |
| Date | 2011-06-13 11:12 +1200 |
| Message-ID | <95kvfnFrhmU4@mid.individual.net> (permalink) |
| References | <ab6caee2-a808-4158-9602-fc51935307eb@d1g2000yqk.googlegroups.com> |
On 06/13/11 11:05 AM, papoupapa wrote:
> Hi
You asked almost the same question on c.l.c, very confusing!
> I reay think // A should be (nbr_entry != 0) || (i< NMAX) instead
> of (nbr_entry != 0)&& (i< NMAX)
Why? You want to keep reading while both conditions are true, not just one.
> As it's working, to my understanding, the second body of the for loop
> is being read from the left to the right.
>
> int main()
> {
> const int NMAX = 5 ;
> vector<int>Numbers(NMAX) ;
> int nbr_entry = 1 ;
> int i, j ;
>
> cout<< "\nThis program reads a sequence of numbers \n" ;
>
> j = 0 ;
> nbr_entry = 1 ;
> for (i = 0 ; (nbr_entry != 0)&& (i< NMAX) ; i++, j++) // A
> {
> cout<< "\nValue "<< i+1<< " : " ;
> cin>> nbr_entry ;
> Numbers[i] = nbr_entry ;
> }
>
> cout<< "\n\nNumbers entered : \n" ;
>
> for (i = 0 ; i< j ; i++)
> cout<< "Value "<< i+1<< ": "<< Numbers[i]<< "\n" ;
>
>
> cout<< "\n\n" ;
> system("pause") ;
> return 0 ;
> }
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
simple for loop i find not coherent papoupapa <papoupapoug@gmail.com> - 2011-06-12 16:05 -0700 Re: simple for loop i find not coherent Ian Collins <ian-news@hotmail.com> - 2011-06-13 11:12 +1200
csiph-web