This program seems logical and will probably work. However, the second task is quite hard, if not impossible. The part where the sensor reads black and goes forward is easy:

However, the part where the sensor is outside of the line is impossible. Let us say that the robot is on the right side of the line:

Then it has to turn left to return to the line. Now, if the sensor is on the left side of the line:

It has to turn right to return to the line. That is great but the values the sensor reads on both sides of the line are close if not the same. Hence the robot will not know if it has to turn left or right.
That is why, when we say that we program the robot to follow a line, we usually lie. The truth is that the robot is not following the line but one of its edges.
The edge is an imaginary line which separates the line from the other part of the field (the red dotted lines on the image above). So the line has two edges - one on its left side and one on its right side.
When we are following the edge of the line, the robot, which uses only one color sensor, knows if it is on the left or on the right side of the edge it follows. For clarity, let us assume that the robot is following the right edge of the line. So, if the sensor reads black, this means the robot is on the left side of the edge and should turn right:

If the sensor reads white, it is on the right side of the edge and should turn left:

Having said that, the program for following a black line should look like this - if the sensor reads black, it turns right, otherwise it turns left. Of course, this check is repeated in a loop. Go through the next few exercises and then try and see if the robot follows the line successfully.