Friday, December 10, 2010

12/10 Blog Reflection

This week we worked on for and do while loops. For loops set the parameters like this:

for(int x = 1; x<=4; x=x+1)
{
System.out.print("run");
}

The section closest to the "for" (x=1) is setting the initial value of the int x. The next part, "x<=4", sets the value that once reached by the designated variable (x), makes the loop stop. The last piece, "x=x+1" makes it so that every time the loop runs, the variable x increases by 1. The output would be

run
run
run
run

This is because once the value of x hits 4, the code runs once and then stops. The value of the x, displayed in the run is:

(1)
run
(2)
run
(3)
run
(4)
run

Do While loops are different from for loops because for loops check the requirements before running. Do Whiles, on the other hand, check the requirements after running. The approximate code that is similar to the above code is this:

int x = 1
do{
System.out.println("run");
x++;
}while( x<=4);
The output of this would be:

run
run
run
run

with variables shown:

(1)
run
(2)
run
(3)
run
(4)
run
(5)

This code, although the output is unchanged, shows the difference between Do While loops and For loops. The Do While checks the criteria after it runs, while the For Loop checks before.

One of the main problems I have is distinguishing where I should use Do While vs. where I should use For Loops. I think that you should use Do While when you want the code to run at least once. For example, in the "PasswordCheck" lab. It had to ask you to enter your password at least once before it could consider whether your response was correct or not. The code for that was very difficult to write. I think that For Loops are simpler and easier to write than Do While, which is why I employ them more frequently in my code.
For loops are probably one of my favorite parts about programming. I really get it. I like having one line of code to make many instances of things. Using input with certain loops is really easy as well. This was another interesting look at the possibilities of shortening code, and making it easier to code faster and more efficiently. I really like do while loops because the code runs at least once. The one lab that we did called "PasswordCheck", I thought, was really interesting, as a password is something actually useful and until recently we hadn't been doing that many things that were practical. I figured out the lab in no time. For a correct password, the computer would print "ACCEPTED" and for the incorrect password it would print "DENIED". It was a fun program to write.
This really made me think about how our programs could be implemented. We have been doing things that have not seemed as real to me as a password check. One of things I really enjoy is the graphics labs we do. More recently, the "Random Colored Boxes" lab was one of my favorite yet. I really enjoyed making something that actually looked cool. Greg Lyons, one of the smartest people I know, managed to make the four seasons in each corner of his random color box. It was impressive, to say the least. While I did not achieve anything like that, I did mess around with making the colors lighter or darker. I really enjoy using For Loops, so Nested For Loops were an obvious next step in my programming learning.
I wonder what else we have to learn about graphics and input. The rock paper scissors lab that we did really intrigued me. In class, we had actually made a functioning game. Sure, the game was based off of crude booleans and input, but it was still fun (maybe it's just fun to see your code work!). My friend Zoli made a really cool snake game, and Tron game using Java (may have been JavaScript, actually). I was very impressed, and asked Zoli to show me how to do what he did. He just laughed, and told me I had a lot to learn about programming before I could do something like that. I can't wait to learn all that I can about Java and to be able to program at that level


This port is a revamp of a post reflection 11/21 (http://frankblogfrankblog.blogspot.com/2010/11/reflection-1121.html)

Thanks for reading!
Frank