Photoresistance

Hello, I found this code and i understand that according the amount of light on the photoresistor will determine how much the servo moves in degrees. I want to learn what each line means specifically.
I do not get fully get from the ()loop to the bottom,
can someone please clarify?
Thanks

#include <Servo.h>
const int photocellPin = A0;
Servo myservo;
int outputValue=0;
int angle[]={0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180};
int maxVal=0;
int maxPos=0;

void setup()
{
  myservo.attach(9);
}
void loop()
{
  for(int i=0; i<19; i ++)
  {
    myservo.write(angle[i]);
    outputValue = analogRead(photocellPin);
    if(outputValue > maxVal)
    {
      maxVal = outputValue;
      maxPos =i;
    }
  delay(200);
  }
  myservo.write(angle[maxPos]);
  while(1);
}

Since the loop() has this statement at the end, it stops after one iteration.

while(1);   // blocks here !!

so it doesn't do very much.
But it does appear to be an attempt, as the light level ramps up, to move the servo.

Where did you find this code and what do you want to achieve? Getting the ambient light level to control the movement of a servo is not really a difficult task.

6v6gt:
Since the loop() has this statement at the end, it stops after one iteration.

while(1);   // blocks here !!

so it doesn't do very much.
But it does appear to be an attempt, as the light level ramps up, to move the servo.

Where did you find this code and what do you want to achieve? Getting the ambient light level to control the movement of a servo is not really a difficult task.

i got the code from when i bought an Arduino starter kit and the only info that it gave was that it is supposed to have a photoresistor that will stop at the brightest position.

The code moves the servo to each of the positions in the array and takes a reading from the sensor. As it goes it saves the maximum reading in maxVal. It also saves the index number for the maximum reading in maxPos.

It then moves the servo to the position at which the maximum value was detected and enters the unending WHILE loop which effectively stops things.

...R

It looks like an exercise from this starter kit:

The servo keeps moving the LDR (light dependent resistor) until the maximum light level is not exceeded, then stops.

Have you actually tried this exercise and, if so, how does it respond ?

post crossed with @Robin2