0

Can't someone fix all this challenges?

It's not really an infinite loop. https://prnt.sc/ntnms7

26th May 2019, 9:38 PM
stnwtr
8 Respostas
+ 3
Here you can see it: https://code.sololearn.com/c6BdfR5B0UBC/?ref=app A do while loop executes once and then checks the condition. If the condition is true, repeat the loop. A while loop checks first the condition and only if the condition is true it executes the code.
26th May 2019, 9:54 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Have you tried it in the code playground? It is an infinite loop. int x = 0; Do{ System.out.println(x); //output: 0 x++; //x = 1 }while (x > 0) //true -> 1 > 0
26th May 2019, 9:50 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
No it is not. x will reach Integer.MAX_VALUE after a time and then adding 1 to it will set it to Integer.MIN_VALUE which is -2^31. Denise Roßberg
26th May 2019, 9:57 PM
stnwtr
26th May 2019, 10:04 PM
stnwtr
+ 1
Real infinity does not exist either. No matter which data type you choose (int, long, BigInteger), you will find a technical barrier. But theoretically, this condition leads to an infinite loop.
26th May 2019, 10:22 PM
Denise Roßberg
Denise Roßberg - avatar
0
Denise Roßberg My problem is not about condition checking, it is about the variable size of an int.
26th May 2019, 10:01 PM
stnwtr
0
A while(true) loop would be pretty much infinite. Or just a different break condition would help
26th May 2019, 10:28 PM
stnwtr
0
stnwtr Nice observation!
26th May 2019, 10:38 PM
vlada