Sign in to follow this  
Kryptus

Foreach loop exit?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this