[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Labs] [Assignments] [Examples] [Bailey Docs] [SamR Docs] [Tutorial] [API]
Held: Wednesday, January 28, 1998
% elm -s "Homework 1" rebelsky < scriptfile
while loopwhile loop, which has
the form
while (test)
{
statements;
} // while
while loop
called the do loop, and has the form
do
{
statements
} while (test);
for loop
for (initialization; test; increment)
{
statement;
} // for
initialization;
while (test)
{
statement;
increment;
} // while (test)
for loop can be omitted
(in which case it is ignored).
int i; // A counter variable
int factorial; // The factorial of N
factorial = 1;
for (i = 1; i <= N; i = i+1)
{
factorial = factorial * i;
} // for
var++.
++ can be used before or after any variable
(or reference to a memory location). The effect is to increment
the variable by one (or an equivalent of one).
-- can be used to decrement the variable by
one.
++ and -- with integer
variables (and their variants).
++ comes before the variable, the value of the
expression is the new value of the variable.
++ comes after the variable, the value of the
expression is the old value of the variable.
break exits the current loop (or switch).
continue exits the current repetition of the loop
(going back to the test, and, possibly, to another repetition of
the loop).
label: statement and then use
break label to break out of that statement.
For example
outer:
for (i = 0; i < N; ++i)
{
inner:
for (j= 0; j < M; ++j)
{
if (meetsCondition(i,j))
{
out.println(
"Found what we were looking for at (" +
i + "," + j + ")"
);
break outer;
} // if
} // inner for loop
// Here's where you go if you break out of the inner loop
} // outer for loop
// Here's where you go if you break out of the outer loop
continue can take a label, and returns to the
next iteration of the labeled loop.
DrawableObject class
and refine that to particular drawable objects, such as Circle
or Square.
extends keyword.
public class Circle
extends DrawableObject
{
...
} // Circle
DrawableObject obj = new Circle();
public void drawWithStrangeColors(DrawableObject obj)
{
...
} // drawWithStrangeColors(DrawableObject)
...
drawWithStrangeColors(new Circle());
extends clause,
Java assumes that your object extends java.lang.Object.
On to Interfaces and More
Back to Lab: Building Classes
Outlines:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Current position in syllabus
[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Labs] [Assignments] [Examples] [Bailey Docs] [SamR Docs] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/98S/home/rebelsky/public_html/Courses/CS152/98S/Outlines/outline.07.html
Source text last modified Tue Jan 12 11:52:17 1999.
This page generated on Mon Jan 25 09:48:49 1999 by SiteWeaver. Validate this page.
Contact our webmaster at rebelsky@math.grin.edu