+ 6
ANY OTHER WAYS FOR CREATING INFINITE LOOP USING JAVA?
class Infinity { public static void main(String args[]) { int a=1; for(;;) { System.out.println(a); } } } OTHER THAN THIS?
33 Respuestas
+ 20
while(true) {
// do whatever
};
do {
// do whatever
} while(true);
+ 9
String[] focus = {
"Follow",
"One",
"Course",
"Until",
"Success"
};
int i=0;
int len=focus.length;
while(i<len); {
System.out.println(focus[i++]);
} // 🍻
+ 6
yes its basicly different. a state of method call are saved in stack memory, so doing recrusion could fill up the stack. once its full Stackoverflow error will occur.
so theoretically, its possible using recrusion as infinite loop. but due the limitation of the stack memory, its not possible.
+ 6
Yes, it's reserved as a keyword Ace. Gosling might have thought it was necessary at the beginning, but it was never implemented :)
+ 5
What Seb TheS said, infinite recursion simulates an infinite loop but isn't exactly the same. And it is possible in Java.
while (true){
//code
}
for(int i = 1;i!=0;i++){
//code
}
do{
//code
}while(true);
+ 5
Phanwadee Suriyaphen I don't believe you need the semi colon at the end of the while loop.
+ 4
Kartikey Sahu You can't use goto in Java.
+ 4
Seems like readability was the reason to remove goto:
https://stackoverflow.com/a/4547764
Comprehensible.
(The true reason might be laziness tho Kartikey Sahu :D )
+ 3
No dude not for Hacking....Just for my knowledge.
+ 3
If your condition was wrong ❌ the program is infinte loop
Ex: in python
A=5
While(A>1) :
A+=1
Print(A)
+ 2
Atleast recursion, (function calling itself).
If you could make the program to run itself again, using command prompt or similar it could also make infinite loop, but I don't know whether it's possible with Java, propably yes.
+ 2
for(;;)
+ 2
for(;true;)
{
System.out.println("hii");
}
+ 2
Infinite loops are usually very bad coding style... You have to avoid them...
+ 2
YES ask your expert
+ 2
for(int i=0;i<=0;i++){
System.out.println(i);
i--;
}
+ 2
Kartikey Sahu why was Gosling lazy?
+ 1
In any loop(for,while,do while,), and recursive function, after start of execution, if there is no base condition or exit condition to exit, then loops infinitely.
Adding to above examples:
(Tashi N, kilowac said..)
returntype fun(...){
--
fun(...);
--
}
Ex:
int fun(int i){
return i*fun(i-1);
}
+ 1
while(true);
for(;;);
+ 1
}
While(){
}