Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginners question

Status
Not open for further replies.

lfc77

Programmer
Aug 12, 2003
218
GB
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?

Cheers,

lfc77
 
Can you say what you're trying to achieve as simply exiting all execution in the middle of itself seems a little odd.

Rhys
Buffy: Spike, what are you doing here, five words or less!
Spike: Out for a walk... bitch!
 
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.

lfc77
 
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.'

Code:
if (x==1 && y==2 && z==3)
{
//do something
}
else
{
//do something else
}

Can you post a little code if this is not at all what you're trying to achieve, just in case I'm completely missing the point :)


Rhys
Buffy: Spike, what are you doing here, five words or less!
Spike: Out for a walk... bitch!
 
Apologies, I was just being extremely dense...!
 
You can also use the "break" keyword to skip to the statement following control block you're currently in.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top