0
for (var x=0;x==x;x++) { if (x>5&&x<8) { document.write(x); } }
what is the output ? how such loops execute? plz explain me..I am confused with middle condition in d above example
14 Answers
+ 8
no problem! Some frustrated guy is down voting all my comments/codes with 5 different accounts lol
+ 7
What are you trying to do exactly ? for (var x=0;x==x;x++) this loop is wrong.
x == x is always true and the loop will never end. So the output will be 6 7 6 7 6 7.... 6 7 forever.
+ 7
What you are writing is like writing this :
int x = 0;
while (true){
x++;
if ( x > 5 && x < 8) { System.out.println(x);}
}
Because the condition is always true the compiler will implement x and jump to 5<x<8 and print it. Then again it will jump there and print it and then again and again.
If you remove the if statement you will print all integer values and it will not jump to any value.
If you change 5 and 8 with some bigger numbers you will notice the jump more.
+ 5
Yes it will not print anything and it's infinite loop.... if I am correct, you're trying to check the answer for 1 of the question in JS challenge right?
for (var x=0;x==x;x++)
{
if (x >5 || x <8)
{
document.write (x);
break;
}
}
In this case, in the seventh iteration I.e x=6, if condition is true. so it will print 6 and breaks the loop.
This is what you're looking for?
Otherwise as I said, your code will cause infinite loop and it won't print anything.
+ 1
but if condition inside it is not becoming true then how it will print output.. I'm confused.. explain more
+ 1
thnx venki
+ 1
thnx r2d2
+ 1
i'm lost
0
what is this
0
wow am a beginner in java i will like to learn from you
0
oh excuse me, I did not know I was in html
0
The loop is infinite because the condition is always true. Try to put x<9 in the condition, then your code will print your message 2 times.
0
parrotsegurity
0
hacker