Site hosted by Angelfire.com: Build your free website today!
Assignment 2




Assignment 2 is one of, if not, the first looping programs I wrote using KarelJRobot while at Strake. It is quite simple, but like its predecessors in JOptionPane, it is nonetheless very effective in showing what loops can do. Consider the following code.



Code



This program tells the robot karel to start at the first corner facing in the blankworld, and while facing north put a beeper and move while the count is less than nine. The program first defines the count and then, under a while loop, tells the robot to put a beeper and move while it has done so less than nine times. These types of loops, while not necessary, are useful in reducing the amount of code one needs to write. Look at the result below.




World


World


The loop causes the robot to move and put a beeper nine times. But instead of having to write the commands nine times, the loop allows the code to be nice and concise.

Look at the other looping programs below if you have not already.
    Student Name
    Shirt Size

You can also return to the Loops main page here.


Or, if you are not currently interested in learning about Loops, you can return to my home page to experience other aspects of Java programming.


Last updated May 7, 2005