473,804 Members | 3,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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++)
{
SafeArrayPutEle ment(psaArray, &lVal, &j);

}

Thanks!

Nov 28 '05 #1
7 1966
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++)
{
SafeArrayPutEle ment(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++)
{
SafeArrayPutEle ment(psaArray, &lVal, &j);

}


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

Nov 28 '05 #3
In article <11************ *********@z14g2 000cwz.googlegr oups.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++)
{
SafeArrayPutEle ment(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++)
{
SafeArrayPutEle ment(psaArray, &lVal, &j);

}

SafeArrayPutEle ment 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,r gsaBound);

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,r gsaBound);


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,r gsaBound);


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
5267
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 have a programmable exit condition. It keeps looping till the channels in its socket map (a dictionary) are closed and don't have any pending reads/writes. If you are using Python threads in your application, by using either the threading or...
6
4794
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 in the for loop. I am including the portion of the code : #Get the connection to the database my $dbh = &getConnection(); my @acodes;
47
12350
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) { int result = 0; for(int i = 1;i <=iterations;i++) { result += i;
15
2540
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 row it stops.. At least that's what I thought I did, but VC71 says "warning C4717: 'LOOP<0,1>::DO' : recursive on all control paths, function will cause runtime stack overflow". What's wrong? Here's the code: template<int M, int N>
21
18766
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 nanosleep(), depending on platform }
10
2321
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* and use it to load an texture from some outside functions. My problem lies in the "for loop", the Code goes as follows. //I create the array of pointers, I'm using 2 just for the sake of an example MapTextures = new unsigned int;
16
3548
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 instructions which can sure be optimized away is the check for the break condition, at least within the time where it is known that the loop will not reach it. Any idea how to write such a loop? e.g.
29
5121
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: 65,535. But i'm trying to write a program to test this, assuming I didn't know this number in advance. I came up with the following but have two questions. Maybe someone can help? using System; using System.Collections.Generic; using System.Text;
44
4320
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
1839
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 %c",x,x); }
0
10575
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7616
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.