looping problem

I need to restart a loop with some variable changed. I’ve tried this but the loop stops without changing anything:

void CheckTrajectory(Vector3 target)
    {
        Debug.Log("checking");


        loopEnd = false;
        angleJump = 0;

            while(angleJump < 90f && !loopEnd )
        {
            Scan(target);
        }

        if(angleJump < 85)
        {
            rigidbody.velocity = BallisticVel(target,angleJump);
        } else
        {
            //Calculate No Arc
        }

    }

void Scan(Vector3 target)
    {

             angle_jump = CalculateAngle(target);
             startingVelocity = BallisticVel(target, angle_jump);
             heightTime = startingVelocity.y/-Physics.gravity.y;

        for (int i = 0; i < heightTime*60; i++) 
            { 
                Debug.Log(i);
                Vector3 trajectoryPosition = TrajectoryPoint( transform.position, startingVelocity, i );
                Debug.Log(trajectoryPosition);

            Debug.DrawRay(trajectoryPosition,dir,Color.red,10f);

            RaycastHit hit;
            if(Physics.Raycast(trajectoryPosition,dir,out hit,collider.bounds.extents.z,mask))
                {
                    angleJump +=10;
                    Debug.Log(hit.collider.name);
                    break;
                }
                else if(i == heightTime*60)
                {
                    loopEnd = true;
                    Debug.Log("endloop");
                }else
                {
                    Debug.Log("continuing");
                    continue;
                }
            }

}

I think you’re misunderstanding how break and continue work a bit, at no stage wiill break “restart” your loop:

for (int i = 0; i < 10; ++i)
{
   if (someCondition)
   {
     continue;
   }
   else if (anotherCondition)
   {
     break;
   }
   
   doSomething();
}

afterLoop();

The body of the above loop will iterate up to 10 times. In any given iteration:

  • If someCondition is true, continue will be called, causing the loop to skip to the next iteration (doSomething will not be called for the current iteration, i will be incremented, and if it’s still below 10 the next iteration will run)
  • Otherwise if anotherCondition is true, break will be called, causing the loop to terminate. doSomething will not be called for this iteration, i will not be incremented again, and execution will now continue from afterLoop()
  • Finally if neither of these conditions are true, doSomething() will be reached and executed, i will be incremented, and if it’s still below the next iteration will start