How to stop my Loop if the value is already existing?
here's my code in C#...
foreach (ArrayList item in ArrData)
{
HCSProvider.NewProviderResult oResult;
oResult = oHCSProvider.CreateNewProvider(providercode, oProviderDetail)
DBInterface ProviderDetail = new DBInterface();
ProviderDetail.InsertProvider(Convert.ToInt64(providercode), Convert.ToString(oProviderDetail));
}
break command (C and C++) The break command allows you to terminate and exit a loop (that is, do , for , and while ) or switch command from any point other than the logical end. You can place a break command only in the body of a looping command or in the body of a switch command.
There is no way to stop an infinite loop. However, you can add a condition inside of the loop that causes it to break, or you can call the exit() function inside of the loop, which will terminate your program. Highly active question.
break terminates the execution of a for or while loop. Statements in the loop after the break statement do not execute. In nested loops, break exits only from the loop in which it occurs.
To break out of a while loop, you can use the endloop, continue, resume, or return statement.
you can skip iteration with
continue;
and stop loop with
break;
If you are inside a loop and want to abort the loop execution and jump to the code after the loop, insert a break;
statement.
If you only want to stop the current loop iteration, and continue with the rest of the loop, add a continue;
statement instead.
You can stop any loop in c# by a break
statement
You can write something like this:
foreach(var o in list)
{
if (o.SomeValue == 1)
{
break;
}
}
Continue, break and goto are used in C# for skipping the loop.
Continue Skips the execution of current iteration
Continue;
break Comes out of the loop and continues the next statement after the loop
break;
goto is normally not recommend, but still can be used to move control out of the loop
goto Outer;
You can put a break command to exit from For Loop.
foreach(var item in items)
{
if(item == myitem)
{
break;
}
Console.WriteLine(item);
}
you can easily stop your lop on a condition with the break statement!
Small example:
var arr = new [] {1,2,3,4,5,6,7};
int temp = 0;
foreach(var item in arr)
{
temp = item +1;
if(temp == 5)
{
break;
//...
}
//do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With