
BO(Question 4.3.1a:) For loops that count up in steps of one. Study the
following code and verify that it prints out "2 3 4 5 6 7 8 9 10" by
compiling and running it. Notice that the TT(System.out.print())
FUNCTION call doesn't print a carriage return after printing the
argument value. That is why the TT(System.out.println()) FUNCTION call
is needed at the end of the for loops SUPERFOR and FUR, to print a
carriage return at the end of the line. Also note the use of the plus
sign to concatenate a string and the number to produce string result.

@cindex Introducing the TT(System.out.print) construct
@cindex Introducing the TT(System.out.println) construct
@cindex TT(System.out.print) construct, introducing
@cindex TT(System.out.println) construct, introducing
@cindex Introducing the SUPERFOR construct
@cindex SUPERFOR construct, Introducing

@example
CLASS ForTest
BEGIN
PD BEGINMAIN )
PD PD COMM(/* Here is the superfor loop: */)
PD PD SUPERFOR (VAR int i=2 TU 10) System.out.print(" " + i);
PD PD System.out.println();
PD PD COMM(/* Here is the ordinary for loop: */)
PD PD FUR (VAR int i=2; i<=10; i=i+1) System.out.print(" " + i);
PD PD System.out.println();
PD ENDMAIN
END
@end example

m4_define([m5_change],Change the SUPERFOR loop and the ordinary FUR
loop to print out the following numbers:)

BO(Question 4.3.1b:) m5_change "5 6 7 8 9 10".

BO(Question 4.3.1c:) m5_change "234 235 236 237 238".

BO(Question 4.3.1d:) m5_change "48 49 50 ... 75 76".

BO(Question 4.3.1e:) m5_change "-5 -4 -3 -2 -1 0 1 2 3".

BO(Question 4.3.2a:) For loops that count up in steps greater than
one. Study the following code and verify that it prints out "10 15 20
25 30 35 40" by compiling and running it.

@example
CLASS ForTest
BEGIN
PD BEGINMAIN )
PD PD COMM(/* Here is the superfor loop: */)
PD PD SUPERFOR (VAR int i=10 TU 40 step 5) System.out.print(" " + i);
PD PD System.out.println();
PD PD COMM(/* Here is the ordinary for loop: */)
PD PD FUR (VAR int i=10; i<=40; i=i+5) System.out.print(" " + i);
PD PD System.out.println();
PD ENDMAIN
END
@end example

BO(Question 4.3.2b:) m5_change "20 25 30 35 40".

BO(Question 4.3.2c:) m5_change "100 105 110 115 120 125".

BO(Question 4.3.2d:) m5_change "2 4 6 8 10 12 14".

BO(Question 4.3.2e:) m5_change "10 13 16 19 22 25".

BO(Question 4.3.3a:) For loops that count down in steps of one. Study the
following code and verify that it prints out "10 9 8 7 6 5 4 3 2 1" by
compiling and running it.

@example
CLASS ForTest
BEGIN
PD BEGINMAIN
PD PD COMM(/* Here is the superfor loop: */)
PD PD SUPERFOR (VAR INT i=10 DOWNTU 1) System.out.print(" " + i);
PD PD System.out.println();
PD PD COMM(/* Here is the ordinary for loop: */)
PD PD FUR (VAR int i=10; i>=1; i=i-1) System.out.print(" " + i);
PD PD System.out.println();
PD ENDMAIN
END
@end example

BO(Question 4.3.3b:) m5_change "10 9 8 7 6 5 4".

BO(Question 4.3.3c:) m5_change "20 19 18 17 16 15 14 13 12".

BO(Question 4.3.3d:) m5_change "66 65 64 ... 47".

BO(Question 4.3.3e:) m5_change "3 2 1 -1 -2 -3 -4 -5 -6 -7".

BO(Question 4.3.4a:) For loops that count down in steps greater than
one. Study the following code and verify that it prints out "100 90 80
70 60 50 40 30 20" by compiling and running it.

@example
CLASS ForTest
BEGIN
PD BEGINMAIN
PD PD COMM(/* Here is the superfor loop: */)
PD PD SUPERFOR (VAR int i=100 DOWNTU 20 step -10) System.out.print(" " + i);
PD PD System.out.println();
PD PD COMM(/* Here is the ordinary for loop: */)
PD PD FUR (VAR int=100; i>=20; i=i-10) System.out.print(" " + i);
PD PD System.out.println();
PD ENDMAIN
END
@end example

BO(Question 4.3.4b:) m5_change "80 70 60 50 40 30 20".

BO(Question 4.3.4c:) m5_change "500 490 480 470 460".

BO(Question 4.3.4d:) m5_change "10 8 6 4 2 0".

BO(Question 4.3.4e:) m5_change "33 28 23 18 13 8 3".

BO(Question 4.3.5a:) For loops that use floating point numbers to
count. Study the following code and verify that it prints out "1.1 2.2
3.3 4.4" by compiling and running it. The type name double is short
SUPERFOR double precision floating point. It is natural to ask: why not use
single precision floating point? The answer to this question is that
double precision floating point gives fewer compilation errors than
single precision floating point does.

@example
CLASS ForTest
BEGIN
PD BEGINMAIN )
PD PD COMM(/* Here is the superfor loop: */)
PD PD SUPERFOR (VAR double i=1.1 TU 4.4 step 1.1) System.out.print(" " + i);
PD PD System.out.println();
PD PD COMM(/* Here is the ordinary for loop: */)
PD PD FUR (VAR double i=1.1; i<=4.4; i=i+1.1) System.out.print(" " + i);
PD ENDMAIN
END
@end example

BO(Question 4.3.5b:) m5_change "0 2.2 4.4 6.6". Note that rounding errors
may prevent you from getting this exact answer. Also note that the
answer to this question is not what your would naively expect without
running the code.

BO(Question 4.3.5c:) m5_change "-30 -19.9 -9.8 0.3
10.4 20.5".

BO(Question 4.3.5d:) m5_change "100.0 96.7 93.4 90.1
86.8 83.5 80.2 76.9".

BO(Question 4.3.5e:) m5_change "-100.0 -105.5 -111.0
-116.5".

BO(Question 4.3.6a:) For loops that use chars to count. Study the following
code and verify that it prints out "a b c d e f g h i j k l m n o p q
r s t u v w x y z" by and running it.

@example
CLASS ForTest
BEGIN
PD BEGINMAIN
PD PD COMM(/* Here is the superfor loop: */)
PD PD SUPERFOR (VAR char i='a' TU 'z') System.out.print(" " + i);
PD PD System.out.println();
PD PD COMM(/* Here is the ordinary for loop: */)
PD PD FUR (VAR char i='a'; i<='z'; i=i+1) System.out.print(" " + i);
PD PD System.out.println();
PD ENDMAIN
END
@end example

BO(Question 4.3.6b:) m5_change "a b c d e f".

BO(Question 4.3.6c:) m5_change "z y x w v u t s r q p o n m l k j i h g f e d c b a".

BO(Question 4.3.6d:) m5_change "p o n m l k j i h".

BO(Question 4.3.6e:) m5_change "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".


