I've got a typical question. I need your assistance. while(var != var) { System.out.println("I'm inside the loop"); } Code (markup): How to declare the variable var (of any data type), so the the while loop runs infinitely? This is possible, I know. But don't know how. Please help. I've used Java here, you can assist me in any other language.
Here's your solution in PHP... while ($var==$var) { echo 'I\'m inside the loop'; } PHP: You were using != which is "not equal to" so if you're checking the same variable against itself the content of echo will never display.
Thanks you all for replying. Fortunately, I searched a lot yesterday and found the answer. My question was correct. Just while(var != var) can create an infinite loop. I've got the solution and I'll like to share it with you. It's basically a floating point value, in Java it's NaN (Not a Number). float var; var= (0f / 0); //zero-f by zero while(var != var) System.out.println("Inside loop"); This code creates an infinite loop. Because a variable with value of NaN is not equal to itself, according to convention and practice.