Tagged Questions
22
votes
24answers
10k views
do…while vs while [duplicate]
Possible Duplicates:
While vs. Do While
When should I use do-while instead of while loops?
I've been programming for a while now (2 years work + 4.5 years degree + 1 year pre-college) and ...
15
votes
1answer
277 views
Performance of different C# loops
There are a number of different way to accomplish the same simple loop though the items of an object in c#.
This has made me wonder if there is any reason be it performance or ease of use, as to ...
9
votes
11answers
12k views
Continue in nested while loops
In this code sample, is there any way to continue on the outer loop from the catch block?
while
{
// outer loop
while
{
// inner loop
try
{
throw;
}
...
8
votes
12answers
7k views
break out of a loop that contains a switch statement (C#)
I am having trouble figuring out how to break out of a loop that contains a switch statement. Break breaks out of the switch, not the loop.
There is probably a more elegant solution to this. I have ...
6
votes
8answers
3k views
How do I find the inner-most exception without using a while loop?
When C# throws an exception, it can have an inner exception. What I want to do is get the inner-most exception, or in other words, the leaf exception that doesn't have an inner exception. I can do ...
6
votes
7answers
386 views
Break a while loop using external event
I have a while loop in a windows service which runs for some x times and inititate x phone calls after reading them from some file . Now if i want to make a user interface which gives an option to ...
5
votes
4answers
2k views
What happens when one places a semi-colon after a while loop's condition?
I've come across a situation like this a few times:
while (true) {
while (age == 5); //What does this semi-colon indicate?
//Code
//Code
//Code
}
The while(true) indicates that this is an ...
5
votes
2answers
169 views
Difference between Release and Debug?
I get an very strange behaviour when I change my Visual Studio 2010 config from Debug to Release:
I have a BackgroundWorker: _bg, in the DoWork I have:
iswaiting = true;
...
4
votes
6answers
2k views
C# - foreach loop within while loop - break out of foreach and continue on the while loop right away?
while (foo() == true)
{
foreach (var x in xs)
{
if (bar(x) == true)
{
//"break;" out of this foreach
//AND "continue;" on the while loop.
}
}
...
4
votes
7answers
6k views
do while loop in C#
Hi I am new to programming in C# can some one give me an example of how to write do while loop in C#
EDIT: FYI I am a VB.NET programming trying to make the move to C#, so I do have experience with ...
4
votes
7answers
1k views
Why is “while” so popular in C#?
The question field is a bit too short to pose my real question. If anyone can recapitulate it better, please feel free.
My real question is this: I'm reading a lot of other people's code in C# these ...
4
votes
7answers
249 views
Slow While loop in C#
I have a while loop and all it does is a method call. I have a timer on the outside of the loop and another timer that incrementally adds up the time the method call takes inside the loop. The outer ...
4
votes
5answers
118 views
Trying to compare chars in C#
I am new to C# I have started learning it to broaden the programming languages to my disposal but I have run into a little problem I did not encounter in neither C nor Java.
I am trying to get a user ...
4
votes
3answers
140 views
Is it possible to have dynamic object properties in .net 4.0
I want to add new properties to an object based on loop iterations, is this possible in .Net? The reason I want to do this is I am looping through rows in an excel spreadsheet and for every ...
3
votes
9answers
318 views
I don't understand the use of “while(true)” and “for(; ;)” loops in C#!
sample code for While(true) loop :
public void HandleConnection()
{
TcpClient tcpClient = tcpListener.AcceptTcpClient();
NetworkStream networkStream = tcpClient.GetStream();
...