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


Groups > comp.lang.c++ > #6664

Re: simple for loop i find not coherent

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: simple for loop i find not coherent
Date Mon, 13 Jun 2011 11:12:55 +1200
Lines 45
Message-ID <95kvfnFrhmU4@mid.individual.net> (permalink)
References <ab6caee2-a808-4158-9602-fc51935307eb@d1g2000yqk.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net 23jgXVsG7I2HMaZXNFMJAACfufKAGzW3q5CeW8DHftsKI9N3tm
Cancel-Lock sha1:ncYoFVVn4uCgV2G5EedY4OLxOEo=
User-Agent Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4
In-Reply-To <ab6caee2-a808-4158-9602-fc51935307eb@d1g2000yqk.googlegroups.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:6664

Show key headers only | View raw


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


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