BO(Question 4.4.1:) Study, compile and run the following code:

@example
CLASS LoopTest
BEGIN
PD FUNCTION INT powerOf2A(INT n)
PD BEGIN
PD PD VAR INT counter = n;
PD PD VAR INT result  = 1;
PD PD WHILE (GT(counter,0))
PD PD BEGIN
PD PD PD result = 2 * result;
PD PD PD counter = counter - 1;
PD PD END
PD PD RETURN result;
PD END

PD FUNCTION INT powerOf2B(INT n)
PD BEGIN
PD PD VAR INT counter = n;
PD PD VAR INT result  = 1;
PD PD DU
PD PD BEGIN
PD PD PD result = 2 * result;
PD PD PD counter = counter - 1;
PD PD END WHILE (GT(counter,0));
PD PD RETURN result;
PD END

PD FUNCTION INT powerOf2C(int n)
PD BEGIN
PD PD VAR INT result = 1;
PD PD FUR (VAR INT counter = n; GT(counter,0); counter = counter - 1)
PD PD BEGIN
PD PD PD result = 2 * result;
PD PD END
PD PD RETURN result;
PD END

PD FUNCTION INT powerOf2D(int n)
PD BEGIN
PD PD VAR INT result = 1;
PD PD SUPERFOR (VAR INT counter=n DOWNTU 1)
PD PD BEGIN
PD PD PD result = 2 * result;
PD PD END
PD PD RETURN result;
PD END

PD  /**
PD   * Prints a row of stars of a given length.
PD   */
PD FUNCTION void printLineC(int length)
PD BEGIN
PD PD FUR (VAR int i = 0; i<length; i=i+1)
PD PD BEGIN
PD PD PD System.out.print("#");
PD PD END
PD PD System.out.println();
PD END

PD BEGINMAIN
PD PD COMM(// For Question 4.4.1 add some code here...)
PD ENDMAIN
END
@end example

@cindex Introducing WHILE loops DU DOTS WHILE loops
@cindex WHILE loop
@cindex DU DOTS WHILE loop
@cindex FUR loop

BO(Question 4.4.2:) To the MAIN FUNCTION add some code to call the
functions TT(powerOf2A), TT(powerOf2B), TT(powerOf2C) and
TT(powerOf2D) to verify that they all return the same result. To
inspect the result you will need to apply the TT(System.out.println())
statement to the values returned by those functions.

BO(Question 4.4.3:) There is a bug in the TT(powerOf2B) FUNCTION
because it does not behave correctly in the case when TT(n) is zero or
less. Put an IF (DOTS) THEN DOTS statement at the top of this FUNCTION
to make it handle the case of zero properly.  Also make it return 1 in
the case that TT(n) is less than zero.

BO(Question 4.4.4:) There is a bug in the TT(powerOf2D) FUNCTION
because it does not behave correctly in the case when n is zero or
negative.  Make it return 1 if TT(n <= 0).  Put an IF (DOTS) THEN DOTS
statement at the top of this FUNCTION to make it handle these cases
properly.  Since this FUNCTION returns an INT, make it return 1 in
these cases.

BO(Question 4.4.5:) By copying the pattern of TT(powerOf2A),
TT(powerOf2B), TT(powerOf2C) and TT(powerOf2D), write functions
TT(printLineA), TT(printLineB) and TT(printLineD) that work
identically to the FUNCTION TT(printLineC), except that they use WHILE
loops, DU loops and SUPERFOR loops, respectively. Add some code to the
MAIN FUNCTION to test them out.

BO(Question 4.4.6:) Based on the previous three questions, is there a best
looping construct? Or does it depend on what the looping construct is
going to be used for?

@cindex The best of the four looping constructs SUPERFOR, FUR, WHILE and DU DOTS WHILE

