473,405 Members | 2,344 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,405 software developers and data experts.

Why my loop does't work?

8
Well, my loop is correct, but it simples stops at the first ocurrence... Can canybody help me??

foreach (string word2 in words)
{
if (wordl[i] == word2)
{
i++;
MessageBox.Show("1");
}
else if (word2 == null)
{
MessageBox.Show("2");
}
else if ((word2.Split('='))[1] == (0).ToString())
{
MessageBox.Show("3");
}
else
{
MessageBox.Show("4");
download[j] = word2;
i++;
j++;
}
}
Jan 24 '10 #1
4 1549
donbock
2,426 Expert 2GB
Please enclose your source code in CODE tags (by highlighting the text and pressing the "#" button). This makes it easier for others to read.

What language is this program written in? It certainly isn't C; and I don't think C++ has a 'foreach' keyword either.

That said ... how sure are you that words contains more than one string? You might try printing out the value of word2 for each pass through the loop to make sure it is what you expect.
Jan 24 '10 #2
dancgr
8
It is c#.
The problem is that the loop occurs once, but when it is suposed to loop(start again) it stops.
I reformulated it:
Expand|Select|Wrap|Line Numbers
  1.             for(; i<=counter; i++)
  2.             {
  3.                 if (wordl[i] == null)
  4.                 continue;
  5.                 if (words[i] == wordl[i])
  6.                 {
  7.                     MessageBox.Show("1");
  8.                 }
  9.                 else if (words[i] == null)
  10.                 { 
  11.                     MessageBox.Show("2"); 
  12.                 }
  13.                 else if ((words[i].Split('='))[1] == "0") 
  14.                 { 
  15.                     MessageBox.Show("3"); 
  16.                 } 
  17.                 else 
  18.                 { 
  19.                     MessageBox.Show("4");
  20.                     download[j] = words[i]; 
  21.                     j++; 
  22.                 } 
  23.                 MessageBox.Show("passo loop");
  24.             }
And before this code, i ran:
Expand|Select|Wrap|Line Numbers
  1.             foreach (string word in words)
  2.             {
  3.                 MessageBox.Show(word);
  4.                 counter++;
  5.             }
And checked everything.
Jan 24 '10 #3
Time
77
Values of i and counter may be getting equal or counter may be becoming greater than i. May be debugging will help..
Jan 25 '10 #4
dancgr
8
The problem is tha debuggin don't result in any errors. It simply works, but in the loop it stops without getting any error...
Jan 25 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: ritterhaus | last post by:
Just a simple bit of code to toggle between two state at intervals... import time for i in range(4): print 'On' time.sleep(1) print 'Off' time.sleep(1) .... SHOULD toggle On and Off four...
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...
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*...
6
by: Shill | last post by:
I have several questions. In C, AFAIU, a for loop is just syntactic sugar for a while loop. for (i1; i2; i3) i4; is equivalent to i1 while (i2) {
4
by: outforblood74 | last post by:
Ok here's the deal, the for each statment using VB 6 doesn't loop all the objects. I would like it to close all the IE browsers that are open, but it doesn't work. And now I'm concerned that its...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
51
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
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:...
8
by: malkarouri | last post by:
Hi everyone, I have an algorithm in which I need to use a loop over a queue on which I push values within the loop, sort of: while not(q.empty()): x = q.get() #process x to get zero or more...
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.