• Enhanced Java for loops anyone?

    PHP is becoming more like java and java is becoming more like PHP. The so called enchanced for loops in java 5 is little different from the foreach loops that you encounter in PHP and some other languages.

    One wonders why the new version of the for loop simply didn’t follow the PHP syntax and chose a new syntax instead. You might be quick to point out the PHP is not strongly typed, that’s just what makes it easier to use.

    This is all about writing:

    int a[];

    int sum = 0;
    for (int i=0; i < a.length : i++) {
    sum += e;
    }

    as:

    int a[];

    int sum = 0;
    for (int e : a)
    sum += e;

    It’s not fewer lines of code, but it certainly is shorter, does it really save you time? not really. Many IDEs have code templates (aka boilerplates) which you can just insert into your source with a couple of keystrokes.

    Monday, January 17th, 2005 at 07:31
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
TOP