Enhanced Java for loops anyone?

January 17, 2005

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.

Posted by raditha at January 17, 2005 7:31 AM
Your Ad Here

 

Jabber  |  Linux  |  mySQL  |  PHP  |  Java  |  Site Map  |  Wiki

Downloads  |  About  |  Links  |  Contact  |  Home

 

Copyright © Raditha Dissanayake 2003 - 2007

Terms of Use  |  Privacy

 

 

January 2005
Sun Mon Tue Wed Thu Fri Sat
            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