Velocity Reviews > C++ > Why is for(int i=0; i < 100; ++i) poor?

# Why is for(int i=0; i < 100; ++i) poor?

utab
Guest
Posts: n/a

 08-28-2006
Why is for(int i=0; i < 100; ++i) poor?

Noah Roberts
Guest
Posts: n/a

 08-28-2006

utab wrote:
> Why is for(int i=0; i < 100; ++i) poor?

poor for what?

utab
Guest
Posts: n/a

 08-28-2006

> poor for what?

I do not know, while looking up for sth inside C++ primer I came up
with an exercise question? That's it.

Frederick Gotham
Guest
Posts: n/a

 08-28-2006
utab posted:

> Why is for(int i=0; i < 100; ++i) poor?

utab, you post here regularly. One would hope that, over time, the quality of

Don't ask questions which we can't answer, unless you want us to give a

Reformulate your question and be specific.

--

Frederick Gotham

utab
Guest
Posts: n/a

 08-28-2006
Frederick, you are following my posts, interesting to have some fans
here

> utab, you post here regularly. One would hope that, over time, the quality of

What is wrong with my question, I have supplied the necessary info.
where I had come up with that if you have an idea and want to share,

Noah Roberts
Guest
Posts: n/a

 08-28-2006

utab wrote:
> > poor for what?

>
> I do not know, while looking up for sth inside C++ primer I came up
> with an exercise question? That's it.

If there is no context then the question is bull **** and you should
ignore it. For loops are totally acceptable for certain tasks and in
fact are often the best way to accomplish things. Generally saying a
for loop is "poor" is bunk.

Now, a better question might be why might you prefer for_each over an
equivelant for loop. There are actually answers to this question.
Using algorithms in the std over your own loops has the possibility of
being faster due to the use of private parts in the standard library.
It is also cleaner for many tasks (though not all) and is something
more C++ programmers should be used to seing. Finally it keeps the
check code from being executed more than once without explicitly
declaring a variable or depending on compiler optimizations to get rid
of it.

Does this mean a for loop is "poor"? Hell no. Maybe that book is
garbage - I don't know as I've never read it.

Thomas J. Gritzan
Guest
Posts: n/a

 08-28-2006
utab schrieb:
> Why is for(int i=0; i < 100; ++i) poor?

To iterate is human, to recurse divine.
-L. Peter Deutsch

There may be many reasons:
* Use of magic number '100'
* Doesn't compile: Missing statement
* Useless, because there are no side effects
* Could be done with a STL algorithm

Depends...

--
Thomas

utab
Guest
Posts: n/a

 08-28-2006
Sorry but maybe I should have asked

why is

for(int i=0; i < 100; ++i)
//process i

is poor?

=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a

 08-28-2006
utab wrote:

> Why is for(int i=0; i < 100; ++i) poor?

Because the units are cents, the you only have an euro at the end.

--
Salu2

Kaz Kylheku
Guest
Posts: n/a

 08-28-2006
utab wrote:
> Sorry but maybe I should have asked
>
> why is
>
> for(int i=0; i < 100; ++i)
> //process i
>
> is poor?

Because it's a syntax error. The for (; syntax must be followed by
a statement.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM sam@nospam.org Cisco 10 05-01-2005 08:49 AM =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 01-27-2005 03:35 PM You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM