We'll start with a few things we know.
B contains the average length of a word in the set.
C is the average length of a word in every line.
If we're in agreement until this, let's see the rest.
A is initially zero before the procedure DoSomething is called the first time.
Every time you call DoSomething, A is assigned with what the function returns.
Now, let's tabulate the values of B, C, and A passed to the DoSomething procedure in the last loop.
The last column in the above picture shows the condition under which the 1 gets added to A (R inside the procedure)
Hope things are clear now. If not, please reply..