CS152
Chris Pollett
Nov 1, 2021
BinTree<Integer> myTree = ...
...
for (Integer i : myTree) {
System.out.println(i);
}
this kind of "for each instance loop" could be written more directly using underlying iterators as:
for (Iterator<Integer> it = myTree.iterator(); it.hasNext();) {
Integer i = it.next();
System.out.println(i);
}
while condition do statement
repeat readln(line) until line[1] = '$'instead of
readln(line); while line[1] <> '$' do readln(line);
for (;;) {
line = read_line(stdin);
if (all_blanks(line)) break;
consume_line(line);
}
typedef int (*int_func) (int);
int summation(int_func f, int low, int high) {
/* assume low <= high */
int total = 0;
int i;
for (i = low; i <= high; i++) {
total += f(i); // (C will automatically dereference
// a function pointer when we attempt to call it.)
}
return total;
}
typedef int (*int_func) (int);
int summation(int_func f, int low, int high) {
/* assume low <= high */
if (low == high) return f(low);
else return f(low) + summation(f, low+1, high);
}
(define summation
(lambda (f low high)
(if (= low high)
(f low) ; then part
(+ (f low)
(summation f (+ low 1) high))))) ; else part
(define summation-with-subtotal
(lambda (f low high subtotal)
(if (= low high)
(+ subtotal (f low))
(summation-with-subtotal f (+ low 1) high (+ subtotal (f low))))))
(define summation
(lambda (f low high)
(summation-with-total f low high 0)))
Which of the following statements is true?
void doDothing(int a, int b, int c, int d) {}
the methods:
void statementList1()
{
myFun1();
myFun2();
myFun3();
myFun4();
}
and
void statementList2()
{
doDothing(
myFun1(),
myFun2(),
myFun3(),
myFun4()
);
}
would have the same effect.