Can any body explain this for loop

publicvoid trymethod(){

int i =0;

for ( foo('A'); foo('B')&&(i<2); foo('C')){

i++ ;

foo('D');

}

}

staticboolean foo(char c){

System.out.print(c);

returntrue;

}

The program runs fine but If I return a char from 'foo()' it does not compile.

[904 byte] By [Dheeraj_Gabaa] at [2007-11-27 9:52:41]
# 1
As soon as you change the return type of the foo method from boolean to char, the termination expression of the for loop becomes invalid.In fact, you cannot use the && operator on anything but boolean operands.
TimTheEnchantora at 2007-7-13 0:21:45 > top of Java-index,Java Essentials,Java Programming...
# 2
if you return a char then the for loop will fail, for loops require booleans so either compare the returned value to another char or rethink your program ;-)What exactly are you trying to do?
ita6cgra at 2007-7-13 0:21:45 > top of Java-index,Java Essentials,Java Programming...
# 3
The second clause in your for loop declaration uses boolean logic (if this do that, etc). Once foo is returning a character, it's no longer returning a boolean so the result can't have boolean logic applied to itDon't ask me how to fix it, I have no idea what you're trying to
georgemca at 2007-7-13 0:21:45 > top of Java-index,Java Essentials,Java Programming...
# 4
The for Loop will execute for boolean condition. if you try to return character, character is not compatible with boolean, thats why compile error occursis it clear
harish.suna at 2007-7-13 0:21:45 > top of Java-index,Java Essentials,Java Programming...
# 5
Thanks everybody.Actually I got confused, I thought that the first expression, in the initialization block of for loop is causing problem. :)Thanks again
Dheeraj_Gabaa at 2007-7-13 0:21:45 > top of Java-index,Java Essentials,Java Programming...