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

for loop does not seem to work

what the heck am I not getting. This little snipet doesn't do what I
thought it was going to do. Can anyone tell me why? I expected
2
Hello: 102

All I get is the 2. I had been trying to iterate though a list that
was not working... please help!

int cnt = 0;
cnt = cnt + 1;
cnt = cnt + 1;
Response.Write(cnt.ToString());
for (int counter = 0; counter == 100; counter++)
{
cnt++;
}
Response.Write("<BR>Hello: " + cnt.ToString());
Nov 15 '05 #1
7 1871
In your for-loop change, "count==100" to "count<100"...

--
Sincerely,

David Sworder
http://www.CodeFanatic.com

"Delphi Sleuth" <hd****@star-telegram.com> wrote in message
news:23**************************@posting.google.c om...
what the heck am I not getting. This little snipet doesn't do what I
thought it was going to do. Can anyone tell me why? I expected
2
Hello: 102

All I get is the 2. I had been trying to iterate though a list that
was not working... please help!

int cnt = 0;
cnt = cnt + 1;
cnt = cnt + 1;
Response.Write(cnt.ToString());
for (int counter = 0; counter == 100; counter++)
{
cnt++;
}
Response.Write("<BR>Hello: " + cnt.ToString());

Nov 15 '05 #2
In your for-loop change, "count==100" to "count<100"...

--
Sincerely,

David Sworder
http://www.CodeFanatic.com

"Delphi Sleuth" <hd****@star-telegram.com> wrote in message
news:23**************************@posting.google.c om...
what the heck am I not getting. This little snipet doesn't do what I
thought it was going to do. Can anyone tell me why? I expected
2
Hello: 102

All I get is the 2. I had been trying to iterate though a list that
was not working... please help!

int cnt = 0;
cnt = cnt + 1;
cnt = cnt + 1;
Response.Write(cnt.ToString());
for (int counter = 0; counter == 100; counter++)
{
cnt++;
}
Response.Write("<BR>Hello: " + cnt.ToString());

Nov 15 '05 #3
That's some weird code...

cnt = 0 (cnt equals zero)
cnt = cnt + 1 (so now cnt equals 1)
cnt = cnt + 1 (so now cnt equals 2)
starting variable "counter" at 0,
and incrementing "counter" by 1,
while the variable 'counter' equals 100
{
increment the variable "cnt" by 1 (and since cnt is already
2...)
}
write the value of the variable "cnt, which will always be 102!
"Delphi Sleuth" <hd****@star-telegram.com> wrote in message
news:23**************************@posting.google.c om...
what the heck am I not getting. This little snipet doesn't do what I
thought it was going to do. Can anyone tell me why? I expected
2
Hello: 102

All I get is the 2. I had been trying to iterate though a list that
was not working... please help!

int cnt = 0;
cnt = cnt + 1;
cnt = cnt + 1;
Response.Write(cnt.ToString());
for (int counter = 0; counter == 100; counter++)
{
cnt++;
}
Response.Write("<BR>Hello: " + cnt.ToString());

Nov 15 '05 #4
That's some weird code...

cnt = 0 (cnt equals zero)
cnt = cnt + 1 (so now cnt equals 1)
cnt = cnt + 1 (so now cnt equals 2)
starting variable "counter" at 0,
and incrementing "counter" by 1,
while the variable 'counter' equals 100
{
increment the variable "cnt" by 1 (and since cnt is already
2...)
}
write the value of the variable "cnt, which will always be 102!
"Delphi Sleuth" <hd****@star-telegram.com> wrote in message
news:23**************************@posting.google.c om...
what the heck am I not getting. This little snipet doesn't do what I
thought it was going to do. Can anyone tell me why? I expected
2
Hello: 102

All I get is the 2. I had been trying to iterate though a list that
was not working... please help!

int cnt = 0;
cnt = cnt + 1;
cnt = cnt + 1;
Response.Write(cnt.ToString());
for (int counter = 0; counter == 100; counter++)
{
cnt++;
}
Response.Write("<BR>Hello: " + cnt.ToString());

Nov 15 '05 #5

"Delphi Sleuth" <hd****@star-telegram.com> wrote in message
news:23**************************@posting.google.c om...
what the heck am I not getting. This little snipet doesn't do what I
thought it was going to do. Can anyone tell me why? I expected
2
Hello: 102

All I get is the 2. I had been trying to iterate though a list that
was not working... please help!

int cnt = 0;
cnt = cnt + 1;
cnt = cnt + 1;
Response.Write(cnt.ToString());
for (int counter = 0; counter == 100; counter++)
{
cnt++;
}
Response.Write("<BR>Hello: " + cnt.ToString());


The for loop says "initialize counter to 0, then run the loop as long as
counter equals 100".

But counter does not equal 100, so the loop doesn't execute.

Try counter < 100

or something like that.
Nov 15 '05 #6

"Delphi Sleuth" <hd****@star-telegram.com> wrote in message
news:23**************************@posting.google.c om...
what the heck am I not getting. This little snipet doesn't do what I
thought it was going to do. Can anyone tell me why? I expected
2
Hello: 102

All I get is the 2. I had been trying to iterate though a list that
was not working... please help!

int cnt = 0;
cnt = cnt + 1;
cnt = cnt + 1;
Response.Write(cnt.ToString());
for (int counter = 0; counter == 100; counter++)
{
cnt++;
}
Response.Write("<BR>Hello: " + cnt.ToString());


The for loop says "initialize counter to 0, then run the loop as long as
counter equals 100".

But counter does not equal 100, so the loop doesn't execute.

Try counter < 100

or something like that.
Nov 15 '05 #7
aaaaa!!! Sorry guys. I had a bad moment. My other language is Delphi
and I confused the two loops. In Delphi the for-loop is more like a
counter. C# as you guys know its more like a while-loop. Excuse my
brain.

- Hal

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #8

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

Similar topics

11
by: Wayne Folta | last post by:
Two observations about PEP-315: 1. It's clever, addresses a definite "wart", and is syntactically similar to try/except. But it's syntax seems like an acquired taste to me. 2. It is a very...
3
by: addi | last post by:
All, I will be eternally greatful if someone can provide snippet of code, URL or reference material that shows how to display data in a "n colums * n rows" format. I am new to ASP and have...
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...
23
by: Mark Anderson | last post by:
A 'for' loop takes 3 arguments (initialize; test; increment). The 'test' must equate as true or false This doesn't work... x = 5; for (y=1; (y==5); y+=1) { alert(x * y); } ...nor does... x...
7
by: Daniel Vallstrom | last post by:
I am having trouble with floating point addition because of the limited accuracy of floating types. Consider e.g. x0 += f(n) where x0 and f are of some floating type. Sometimes x0 is much larger...
63
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
18
by: ma740988 | last post by:
Trying to get more acclimated with the use of function objects. As part of my test, consider: # include <vector> # include <iostream> # include <algorithm> #include <stdexcept> #include...
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...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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...
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...

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.