Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5990347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:13:53+00:00 2026-05-22T23:13:53+00:00

Hi I have something like: Version 1: bool noErrors = true; while(noErrors) { noErrors

  • 0

Hi I have something like:
Version 1:

bool noErrors = true;
while(noErrors)
{
   noErrors = ValidateControl(txtName);

   // other code
}

Version 2:

bool noErrors = true;
while(noErrors)
{
   if(!ValidateControl(txtName)) break;

   // other code
}

I use this code to validate a form and if the validation returns false, I want to break before executing “other code”. Since I do not know when the loop checks for its condition, I do not know which makes more sense. Should I use the first or the second version, or maybe a third one?

Thank you for your time

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:13:53+00:00Added an answer on May 22, 2026 at 11:13 pm

    Version 2 will break before running the //other code. Version 1 will not check until the start of the next iteration.

    bool noErrors = true;
    while(noErrors) 
    {    
        noErrors = ValidateControl(txtName);     
        // other code 
    }
    

    Checks before each iteration.

    bool noErrors = true;
    do 
    {    
        noErrors = ValidateControl(txtName);     
        // other code 
    } while(noErrors);
    

    Checks after each iteration.

    Neither check during an iteration. As stated by the other answerers, the following code simplifies the example but makes me ask the question, is the validity of txtName likely to change during the execution of the loop? Would some other limiting condition be more useful?

    while (ValidateControl(txtName)) 
    {
        // other code 
    } 
    

    If the validity of txtName will not change, consider,

    if (ValidateControl(txtName))
    {
      while(/*Some other condition*/)
      {
          // other code
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this: [Description(Sets the color.), Category(Values), DefaultValue(Color.White), Browsable(true)] public Color MyColor
I have something like this: barProgress.BeginAnimation(RangeBase.ValueProperty, new DoubleAnimation( barProgress.Value, dNextProgressValue, new Duration(TimeSpan.FromSeconds(dDuration))); Now, how
I have something like this: <node TEXT= txt A /> <node TEXT= txt X
I have something like this: <div class=content> <a href=#>A</a> </div> <div class=content> <a href=#>B</a>
I have something like this: Map<String, String> myMap = ...; for(String key : myMap.keySet())
I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I have something like this in my Spring Application: public class Book{ public Book(){
I have something like this in one of my views <li <?php $isCurrent ?
I have something like this: create table account ( id int identity(1,1) primary key,
I have a generic method like this (simplified version): public static TResult PartialInference<T, TResult>(Func<T,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.