
can we pass method in for or while loop....if yes please give example of this.....there is a question in khalid mughel in which loop condition method has being passed.....

Java While Loop
class WhileLoopMethod{
public static void main(String args[]){
new Hello();
}
}
class Hello{
Hello(){
int a = 5, b = 88;
while(a<b){
System.out.println("hh");
a++;
}
}
}

Java While Loop with method
import java.util.*;
class WhileLoopMethod{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
int arr[]=new int[5];
int i=0;
while(input.hasNextInt(5)){
int num=input.nextInt();
arr[i]=num;
i++;
}
for(int j=0;j<arr.length;j++){
System.out.println(arr[j]);
}
}
}