473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

weird FOR LOOP problem (solved)

Bo
Hi, thanks for everyone's help and flames. I think I solved the prob
but was surprised that no one noticed.

Problem:
Given this expression, a, b never increase under my compiler.

double answer=0.0;
for( int i=0, double a=0.0, double b=0.0 ; i<100 ; i++, a+=0.1, b+=0.1
)
answer += i+a+b;

Reason:
because of the required comma separator in the for loop, it is
syntactiacally incorrect to declare both int and double in the for
loop. (though my compiler compiled anyway...)

This works:
double answer=0.0;
int i=0;
for(double a=0.0, b=0.0 ; ... ; ...)
....

The moral? Be careful of abbreviative shortcuts.
Jul 19 '05 #1
2 1656

Bo <sn*****@hotmail.com> wrote in message
news:4f**************************@posting.google.c om...
Hi, thanks for everyone's help and flames. I think I solved the prob
but was surprised that no one noticed.

Problem:
Given this expression, a, b never increase under my compiler.

double answer=0.0;
for( int i=0, double a=0.0, double b=0.0 ; i<100 ; i++, a+=0.1, b+=0.1
)
answer += i+a+b;

Reason:
because of the required comma separator in the for loop, it is
syntactiacally incorrect to declare both int and double in the for
loop. (though my compiler compiled anyway...)

This works:
double answer=0.0;
int i=0;
for(double a=0.0, b=0.0 ; ... ; ...)
...

The moral? Be careful of abbreviative shortcuts.


Better moral: Observe the syntax (and other) rules
of the language.

-Mike

Jul 19 '05 #2

"Bo" <sn*****@hotmail.com> wrote in message
news:4f**************************@posting.google.c om...
Hi, thanks for everyone's help and flames. I think I solved the prob
but was surprised that no one noticed.


At least one person (Stuart Godoletz) did notice.

But you did seem to get a totally unjustified number of flames for a
perfectly good question.

john
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
1
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
0
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
13
by: Dmitry Tkach | last post by:
Hi, everybody! Here is a weird problem, I ran into... I have two huge (80 million rows each) tables (a and b), with id as a PK on both of them and also an FK from b referencing a. When I try to...
10
by: Bonj | last post by:
Hello. I hope somebody can help me on this, because I'm running out of options to turn to. I have almost solved my regular expression function. Basically it works OK if unicode is defined. It...
1
by: petdoc | last post by:
Hi Folks, I am trying to find the most perplexing bug I have had in a vb.net app to date. Here is some code: Dim Data as Short Data = Me.ReadPMAPDigits(pmOffsets.APIAS)
7
by: dtschoepe | last post by:
Hi, I am working on a project for school and I am trying to get my head around something weird. I have a function setup which is used to get an input from stdin and a piece of memory is created...
36
by: Scott | last post by:
Hi, Now this one does not make any sense to me at all. I have a while loop and it is not working anything like it is suppose to. I have placed it below. ------------------------- Count =...
6
by: Emiurgo | last post by:
Hi there to everyone! I've got a problem which may be interesting to some of you, and I'd be very grateful if there is someone who can give me some advice (or maybe redirect me to some other place)....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.