473,386 Members | 1,644 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,386 software developers and data experts.

For Loop Does not End

Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}

Thanks!

Nov 28 '05 #1
7 1949
la******@yahoo.com wrote:
Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}


Your problem is not in this code.

Find out what changes i. Many debuggers have "watch points" which break
when the value of a location in memory changes.
Nov 28 '05 #2
la******@yahoo.com wrote:
Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}


You are sending the address of "j" in the function
"SafeArrayPutElements". Are you modifying the value of "j" there ?
It would be safer to declare "j" as a "const" parameter in function
"SafeArrayPutElements".

Nov 28 '05 #3
In article <11*********************@z14g2000cwz.googlegroups. com>,
la******@yahoo.com wrote:
Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}

Thanks!


You are obviously leaving something out from the code you posted; how do
you know what the value of i is? I don't see any print statements. Could
you post a more complete code snippet?
Nov 28 '05 #4
Ian
la******@yahoo.com wrote:
Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}

SafeArrayPutElement must be doing something smelly on the stack, post
its code.

I'd look for an array that's one too small.

Ian
Nov 28 '05 #5
i++ increments the i value as it goes through the loop. The code
before it just initializes values such as the array, etc.

Code:

long lVal=0;
SafeArray psaArray;
SAFEARRAYBOUND rgsaBound[2];
rgsaBound[0].cElements = 4;
rgsaBound[0].lLbound = 0;
rgsaBound[1].cElements = 3;
rgsaBound[1].lLbound = 0;
psaArray = SafeArrayCreate(VT_VARIANT,2,rgsaBound);

Nov 28 '05 #6
la******@yahoo.com wrote:
i++ increments the i value as it goes through the loop. The code
before it just initializes values such as the array, etc.

Code:

long lVal=0;
SafeArray psaArray;
SAFEARRAYBOUND rgsaBound[2];
rgsaBound[0].cElements = 4;
rgsaBound[0].lLbound = 0;
rgsaBound[1].cElements = 3;
rgsaBound[1].lLbound = 0;
psaArray = SafeArrayCreate(VT_VARIANT,2,rgsaBound);


So?

SafeArray is not a standard C++ type. Neither is SAFEARRAYBOUND.
SafeArrayCreate is not a standard function. Perhaps you should
ask in a newsgroup where they are on topic...

V
Nov 28 '05 #7
la******@yahoo.com wrote:
i++ increments the i value as it goes through the loop. The code
before it just initializes values such as the array, etc.

Code:

long lVal=0;
SafeArray psaArray;
SAFEARRAYBOUND rgsaBound[2];
rgsaBound[0].cElements = 4;
rgsaBound[0].lLbound = 0;
rgsaBound[1].cElements = 3;
rgsaBound[1].lLbound = 0;
psaArray = SafeArrayCreate(VT_VARIANT,2,rgsaBound);


You clearly have a bug in your program. You clearly haven't posted the
part of the code that has the bug yet. Keep trying.

john
Nov 28 '05 #8

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

Similar topics

3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
6
by: Ravi | last post by:
Hi All, I am trying to execute a select statement using the DBI module of perl in a for loop. I am getting a strange behaviour, the select statement is excuting correctly only for the last element...
47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
15
by: Robin Eidissen | last post by:
What I try to do is to iterate over two variables using template metaprogramming. I've specialized it such that when it reaches the end of a row ot starts on the next and when it reaches the last...
21
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
10
by: Nick L | last post by:
I'm working on a function which creates a pointers to an array of unsigned ints based off a number read from a file. I then continue to read file names from the file, convert the name to a char*...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
14
by: shweta khare | last post by:
the range of character constants is from -128 to 127....but in the following program.... main( ) { char x; for(x= -128; x<=127;x++) { printf("\n %d ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.