473,386 Members | 1,908 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.

Very strange loop behavior?

A project that I have been working on has stopped executing loops correctly.
I can add a simple loop to a class in the project, like this:

for (int i = 0; i < 5; i++)
{
Console.Write(i);
}

The 'for' line will execute, then the 'Console.Write()' line, and the focus
jumps to the 'i++' statement. However, the counter 'i' doesn't increment--
it remains at zero after the 'i++' statement is executed. The 'i < 5' still
evaluates to true, but the program immediately exits the loop, as if 'i' had
reached 5.

Has anyone else come across anything like this? Any suggestions on what it
might be? Thanks

David Veeneman
Foresight Systems
Nov 16 '05 #1
4 998
Do you have a watch statement that does something with the 'i' variable?
That could be a likely cause. Does the program work correctly if run without
debugging?

"David Veeneman" <da****@nospam.com> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
A project that I have been working on has stopped executing loops
correctly. I can add a simple loop to a class in the project, like this:

for (int i = 0; i < 5; i++)
{
Console.Write(i);
}

The 'for' line will execute, then the 'Console.Write()' line, and the
focus jumps to the 'i++' statement. However, the counter 'i' doesn't
increment-- it remains at zero after the 'i++' statement is executed. The
'i < 5' still evaluates to true, but the program immediately exits the
loop, as if 'i' had reached 5.

Has anyone else come across anything like this? Any suggestions on what it
might be? Thanks

David Veeneman
Foresight Systems

Nov 16 '05 #2
No, I don't have any watch statements on the code. But I have discovered
that the problem only occurs when I step through the code. When I run it
without breakpoints, it behaves as it should. Any idea what's going on?
Thanks

David Veeneman
Foresight Systems
"Marina" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Do you have a watch statement that does something with the 'i' variable?
That could be a likely cause. Does the program work correctly if run
without debugging?

"David Veeneman" <da****@nospam.com> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
A project that I have been working on has stopped executing loops
correctly. I can add a simple loop to a class in the project, like this:

for (int i = 0; i < 5; i++)
{
Console.Write(i);
}

The 'for' line will execute, then the 'Console.Write()' line, and the
focus jumps to the 'i++' statement. However, the counter 'i' doesn't
increment-- it remains at zero after the 'i++' statement is executed.
The 'i < 5' still evaluates to true, but the program immediately exits
the loop, as if 'i' had reached 5.

Has anyone else come across anything like this? Any suggestions on what
it might be? Thanks

David Veeneman
Foresight Systems


Nov 16 '05 #3
The watch problem is often the cause, since anything done to the variable
during debugging is done on the real thing.

However, if this is really not the case, sounds like a debugger issue. Can
you reproduce this in a new project? Try deleting the dll and recompiling on
your existing project - I wonder if that will fix it.

"David Veeneman" <da****@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
No, I don't have any watch statements on the code. But I have discovered
that the problem only occurs when I step through the code. When I run it
without breakpoints, it behaves as it should. Any idea what's going on?
Thanks

David Veeneman
Foresight Systems
"Marina" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Do you have a watch statement that does something with the 'i' variable?
That could be a likely cause. Does the program work correctly if run
without debugging?

"David Veeneman" <da****@nospam.com> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
A project that I have been working on has stopped executing loops
correctly. I can add a simple loop to a class in the project, like this:

for (int i = 0; i < 5; i++)
{
Console.Write(i);
}

The 'for' line will execute, then the 'Console.Write()' line, and the
focus jumps to the 'i++' statement. However, the counter 'i' doesn't
increment-- it remains at zero after the 'i++' statement is executed.
The 'i < 5' still evaluates to true, but the program immediately exits
the loop, as if 'i' had reached 5.

Has anyone else come across anything like this? Any suggestions on what
it might be? Thanks

David Veeneman
Foresight Systems



Nov 16 '05 #4
Oddly enough, the problem does not occur in new projects. Deleting the DLL
and PDB didn't solve the problem. I'll keep puzzling over this one. Thanks
for your help.
Nov 16 '05 #5

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

Similar topics

4
by: hall | last post by:
Hi. I've come across someting strange. I was trying to make a for-loop execute repetadly until the function called inside it does not return true during the entire loop (see program below). ...
6
by: leonecla | last post by:
Hi everybody, I'm facing a very very strange problem with a very very simple C program... My goal should be to write to a binary file some numbers (integers), each one represented as a sequence...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
2
by: TB | last post by:
I am seeing a very strange problem as follows... I have a loop where a fair amount of processing is going on and near the top of the loop I access a class that has only static helper functions...
4
by: sklett | last post by:
(I posted this in a databinding NG, but it's a VERY low traffic NG so I thought I would post here as well. I hope no one minds too much, if you do I'm sorry) I have a DGV that is bound to a...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...

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.