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

  • SEARCH
  • Home
  • 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 7933447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:20:11+00:00 2026-06-03T21:20:11+00:00

My boolean expression becomes false in the middle of my loop. What kind of

  • 0

My boolean expression becomes false in the middle of my loop. What kind of loop should I use?
I keep reading through loop tutorials and each one mentions that a while loop cannot do this. I’ve tried combining a for loop and an if statement and that doesn’t work either. Sorry for the simple question.

    }
     for(int k = 0;k < collb.length; k++){
        //what was used after first calculation
           grosssum += col4[k]*mix[k];
             one=sum1 - grosssum;


    }
   for(int n = 0;n < collb.length; n++)
    if(one < -need[n] && col4[n] >0){
   col5[n]=col4[n]-inc[n] + arrayspecificpounds[n];
    net += col5[n]*mix[n];
    sum = sum1-net;
 }   //net is the sum of what was used * mix
     //sum1 is what we started with
   else{
     if(one > need[n] && col4[n] >0){
    col5[n]=col4[n]-inc[n] + arrayspecificpounds[n];
    net += col5[n]*mix[n];
    sum = sum1-net;

    }
    else col5[n] = col4[n] +  arrayspecificpounds[n];
    sum = sum1 - net;
   }
   for(int p = 0;p< collb.length; p++){
       if(sum < -need[p] && col5[p] >0){
           col6[p]=col5[p]-inc[p] + arrayspecificpounds[p];
       net2 += col6[p]*mix[p];
       sum2 = sum1 - net2;
       }
     else{
           if(sum > need[p] && col5[p] >0){
               col6[p]=col5[p]+inc[p] + arrayspecificpounds[p];
      net2 += col6[p]*mix[p];
    sum2 = sum1 - net2;
           }
    else col6[p] = col5[p] + arrayspecificpounds[p];
    net2 += col6[p]*mix[p];
    sum2 = sum1 - net2;
   }
    }


        for(int q =0;q< collb.length; q++){
           if(sum2 < -need[q] && col6[q] >0){
               colr[q]=col6[q] - inc[q] +arrayspecificpounds[q];
           }
             else{
               if(sum2 > need[q] && col6[q]>0){
                   colr[q]=col6[q] +inc[q] + arrayspecificpounds[q];
               }
       else colr[q] = col6[q] + arrayspecificpounds[q];
           }    

In this example sum2’s value changes as array col6 is incremented but in the middle of the array the inequalities change. How would I implement a break to stop once sum2 changes?

  • 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-06-03T21:20:13+00:00Added an answer on June 3, 2026 at 9:20 pm

    Here is a simple example of how you can stop a while loop when a boolean value you’re monitoring changes it’s value from false to true:

    boolean done = false;
    int count = 0;
    
    // while not done, continue looping
    while(!done) {
        // do stuff
        count++;
        if(count > 7) {
            done = true;
        }
    }
    

    The same technique can actually be used inside a for loop as well:

    boolean done = false;
    for(int i = 0; i < 1000 && !done; i++) {
        // do stuff
    
        if(i > 7) {
            done = true;
        }
    }
    

    This is a bit unorthodox, but it demonstrates how the 2nd parameter in your for loop can be used to monitor a boolean condition that may or may not be related to the actual value of the int i value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How should the following boolean expression be written in PHP: $foo = ; if($var==TRUE){
Can I use x on both sides of a boolean expression when I post-increment
I need to reduce this boolean expression to its simplest form. Its given that
What is the Visual Basic equivalent of the following C# boolean expression? data.GetType() ==
Is there a way to to evaluate a boolean expression and assign its value
boolean r = false ; int s = 0 ; while (r == false)
boolean isdata=false; // converting this to true String qname=data; String abc=is+qname; isdata = true
In the expression of a while loop, is it possible to initialise a variable,
How could I construct a LINQ expression to remove values from one list that
I have an inline lambda expression that I would like to use throughout my

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.