I know how to exit a procedure that I have called from another procedure (return) to return to the calling procedure, but how do you just exit executing my code in the middle of a procedure?
I have a Page_Load event in my ASP.NET C# website which has a lot of testing for different conditions. If 1 of the conditions isn't met, I want stop executing the rest of the code. I've done this with 'return', but now I have the problem of having a foreach loop where I'm again testing a load of conditions, and on any condition not being met, I need to go to the need element in the loop rather than going through all the other conditions. I've thought of setting a boolean to avoid the rest of the code being executed, but I'd like to know if there is an easy way to just automatically go to the next element.
So you have a 'foreach x in y' type iteration, underneath which you test a number of conditions for each item in the collection you are iterating through. Have you tried evaluating the conditions simultaneously i.e.'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.