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.
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.
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
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