Tuesday, January 24, 2012

Shoop dah Loop

We talked about loops today in class. I already have some experience with them, but now I feel I can write them more confidently. After learning the different types of loops (for, while, do while) I think that the while loop is easiest to understand. Everything about how the loop operates is in one handy location, then you just have to add the loop body, everything is easy to pick out at just a glance. Even though a program runs in an extremely logical and linear (maybe?) fashion, as a programmer it is sometimes easier to code something out of order. I took notes today on a good approach to creating a loop. Creation of a loop: 1. What is it you need to do? (this will be the loop body) 2. How many times does it need to loop? (increment) 3. What will make it stop? (reaching a certain "sentinel" value) 4. How will it stop? (Boolean expression becoming false) Even though these things are usually not in this order when in the code, it is a good way to think about creating a loop until it becomes second nature (hopefully this will happen to me soon, must practice). Also another tip is to simplify errors in code piece by piece. Try to fix parts of an error, testing the program, and then fixing more parts until the error is gone. Don't try to fix an error with one big fix-it-hammer, it hurts to think about fixing a big problem all at once. My knowledge of Java is coming along nicely and I'm actually excited to get into the lab and test what I've learned so far.

1 comment:

  1. You are falling behind the required 3 blogs per week (you should have 6 by now). Please catch up soon or you won't get credit.

    ReplyDelete