The first while loop calculates the value of B using the procedure AddWord.
Sum of letter count of all the words/ Total number of words = 329/65. So, B = 5.077 (approx.)
Just before entering the IF loop of (X. Word ends with a full stop) in the second while loop, the PROCEDURE Sum, Count= AddWord (X, Sum, Count) will calculate and store the Sum value to be the sum of letter count up to the penultimate word in a sentence and the Count value to be the total number of words up to the penultimate word in a sentence, respectively.
Once the last word of every sentence gets picked up, we enter the IF loop as the condition (X.Word ends with a full stop) becomes true and inside this loop, the value of C for the particular sentence is calculated using the stored values of Sum and Count that has been calculated up to the penultimate word of that sentence, as
C = Sum of letter count up to penultimate word in a given sentence / Count of words up to the penultimate word in the sentence.
The Sum and Count value are reset to 0 at the end of each sentence so that for the next sentence, a new value of Sum and Count gets calculated by the procedure Sum, Count, and thereafter the value of C is calculated and compared with B to get the value of A, inside the IF loop.
For the 1st sentence: C = 11/ 3 = 3.66
For the 2nd sentence: C = 32/6 = 5.33
For the 3rd sentence: C = 42/7 = 6
For the 4th sentence: C = 88/20 = 4.4
For the 5th sentence: C = 123/24 = 5.125
PROCEDURE DoSomething (C, B, A)
Compares the values of C with B and return the value of A variable as A+1 if C < B is true, or else return the value of A variable as A itself.
For the 1st sentence: C = 3.66, B = 5.077 , so C < B is True. So, enter the If loop and return the value of A= A+1= 0+1 = 1 (A value gets updated to 1 from the initial value 0 at the end of 1st sentence)
For the 2nd sentence: C = 5.33, B = 5.077, so C < B is false. So, enter the else loop and return the value that’s currently stored in A which is 1.
For the 3rd sentence: C = 6, B = 5.077, so C < B is false. So, enter the else loop and return the value that’s currently stored in A which is 1.
For the 4th sentence: C = 4.4, B = 5.077, so C < B is True. So, enter the If loop and return the value of A = A+1= (current value stored in A variable)+1, which is 1+1 = 2 (A value gets updated a second time to 2 from it's previous stored value 1 at the end of the 4th sentence)
For the 5th sentence: C = 5.125, B = 5.077, so C < B is false. So, enter the else loop and return the value that’s currently stored in A which is 2.