While loop not stopping.

I have a problem with this code, what happens is that the while loop runs infinitely even if the condition is false;therefore,the software bugs out and the second loop doesn’t run. No error messages pop up by the way.

int sangle;

void loop(){
  while ( sangle < 180){ 
  Serial.println("Angle: ");
  Serial.print(sangle);
  Serial.println();
  if(calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP)){
   sOangle = twoP(P1_x, P1_y); 
   sangle = sOangle;
      myservo.write(sangle);
      delay(1000);
      }


  else if(!calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP)){
    //Continue looping
      
      sangle += 1;
      myservo.write(sangle);
        Serial.println("Angle: ");
  Serial.print(sangle);
  Serial.println();
      delay(10);
  }
  }
  
  while ( sangle > 0 ){ 
      Serial.println("Angle: ");
      Serial.print(sangle);
      Serial.println();
      if(calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP)){
      
      sOangle = twoP(P1_x, P1_y); 
      sangle = sOangle;
      myservo.write( sangle);
      delay(1000);

    
  }
  
  
  else if(!calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP)){
    //Continue looping
      sangle += 1;
      myservo.write(sangle);
        Serial.println("Angle: ");
  Serial.print(sangle);
  Serial.println();
      delay(10);
  }
  } 
}

Thanks in advance!

"even if the condition is false"... not at all likely. The compiler is in use by millions of people around the globe. A problem with the while construct would have been spotted by now.

"even if the condition is false"... not at all likely. The compiler is in use by millions of people around the globe. A problem with the while construct would have been spotted by now.

I am not saying that the while loop in general is broken, I am saying that in my case, it doesn't work.

How can you tell the difference? You have the exact identical code inside both while loops.

Bakr: I am not saying that the while loop in general is broken, I am saying that in my case, it doesn't work.

Well, it's almost impossible to know why because the code is undocumented and uncommented other than "// Continue looping", which is not helpful.

How can you tell the difference? You have the exact identical code inside both while loops.

Ah, I now see, sorry for wasting your time. I see the error now.

    if(calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP))
    {
    }
    else if(!calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP))

Since the values in the variables do not change, what is the likelihood that the second call to calculateLine() will return a different result from the first call?

I don't understand crap like this:

 else if(!calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP)){
    //Continue looping

Jammingthecurlybraceupagainsttheendofthestatementandthenwasting

space with useless comments and white space just grates on me.

Bakr:
Ah, I now see, sorry for wasting your time. I see the error now.

These things are much easier to spot if you just use sane and consistent bracketing, spacing, indentation, …

See how much nicer this is to look at and read:

int sangle;

void loop()
{
  while (sangle < 180)
  {
    Serial.println("Angle: ");
    Serial.print(sangle);
    Serial.println();
    
    if (calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP))
    {
      sOangle = twoP(P1_x, P1_y);
      sangle = sOangle;
      myservo.write(sangle);
      delay(1000);
    }
    else if (!calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP))
    {
      //Continue looping
      sangle += 1;
      myservo.write(sangle);
      Serial.println("Angle: ");
      Serial.print(sangle);
      Serial.println();
      delay(10);
    }
  }
  
  while (sangle > 0)
  {
    Serial.println("Angle: ");
    Serial.print(sangle);
    Serial.println();
    
    if (calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP))
    {
      sOangle = twoP(P1_x, P1_y);
      sangle = sOangle;
      myservo.write(sangle);
      delay(1000);
    }
    else if (!calculateLine(CX0,CY0,LftP,0,0,MidP,CX2,CY2,RitP))
    {
      //Continue looping
      sangle += 1;
      myservo.write(sangle);
      Serial.println("Angle: ");
      Serial.print(sangle);
      Serial.println();
      delay(10);
    }
  }
}

PaulS:
Jammingthecurlybraceupagainsttheendofthestatementandthenwasting

space with useless comments and white space just grates on me.

…and changing indentation in the middle of a block.
Also, despite most example code out there, it would be much better for many people to put each bracket on its own line, so you get matching brackets lined up on the same indentation.