• Advertisement
Sign in to follow this  

Foreach loop exit?

This topic is 4606 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a foreach loop here that basically goes through the info in a database and tries the match a user name and password to what the user typed in. What I want to know is how do I stop the loop once the item has been found? // Verify login details and confirm/decline foreach (DataRow dr in dra) { // Verify account name Console.Write("Verifying account name... "); if (Results[0] == dr[7].ToString()) { // Verify password Console.Write("Verifying password... "); if (Results[1] == dr[8].ToString()) { // Verified. How do I leave loop here? } else { // Incorrect password } } else { // Incorrect user name } }

Share this post


Link to post
Share on other sites
Advertisement
'break' is usually the keyword to break out of a loop. However I don't know what language that is so it could be something different.

However if you already have the info in a database, can't you just do a SELECT (or equivilent) to return the row corresponding to the user name, then just check the password?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement