Though I know it\'ll be a bit silly to ask, still I want to inquire more about the technical perspective of it.
A simple example of an infinite loop:
pub
We can achieve it using volatile
variable, which we will change ouside Thread
and stop the loop.
for(;!cancelled;) /*or while(!cancelled)*/{
System.out.println("Stackoverflow");
}
This is better way to write Infinite Loop.
public class LoopInfinite{
private static volatile boolean cancelled=false;
public static void main(String[] args){
for(;!cancelled;) { //or while(!cancelled)
System.out.println("Stackoverflow");
}
}
public void cancel(){
cancelled=true;
}
}