Help me with this java problem /g/. Please explain how this prints 5 times:
for (int j=1; j < 10 ; j = j+1 ) {
for (int i = j-2; ++i < j++; j = i+1)
System.out.println("INF1000");
}
>>51487040
>j = j+1j = i+1
j = i+1
j-2
j < 10
why are you writing such a convoluted clusterfuck anon?
>>51487040
Why the fuck don't you write j++?
>>51488260
>>51487192
ask the professor who wrote the test.
>>51488269
Wow that shit teaches you nothing but DON'T FUCKING WRITE YOUR LOOPS WITH THAT FUCKING MANY INCREMENTS IN THE LOOP DECLARATION
>>51487040
just debug it interactively and step through it ya tard
>>51487040
The inner for loop will always run once and after exiting the inner for loop j will be twice the amount of i when the inner loop starts (int i = j-2+1 or int i = j-1 if you consider the ++i. that will occur after). But really this question is not something that should be done in practice.
int j = 1
j < 10 (1 < 10) true
i = j - 2 (i = -1)
++i < j++ (0 < 1; i = 0; j = 2) true
j = i + 1 (j = 1)
++i < j++ (1 < 1; i = 1; j = 2) false
j = j +1 (j = 3)
j < 10 (3 < 10)
i = j - 2 (i = 1)
++i < j++ (2 < 3; i = 2; j = 4) true
j = i + 1 (j = 3)
++i < j++ (3 < 3; i = 3; j = 4) false
j = j + 1 (j = 5)
...
...
j = j + 1 (j = 7)
...
...
j = j + 1 (j = 9)
...
...
j = j + 1 (j = 11)
j < 10 (11 < 10) false
>>51487040
Why don't you just debug you're code?
>>51488670
it's not MY code, it's a kind of a puzzle on a test
>>51488695
Then input the code to you'rear'e favoright debugger.
>>51487040
Simple. Because "++i < j++" so you're incrementing j twice when "j = i+1". Finally the second loop will only run once each time, so the outer loop runs 5.
>>51488670
>you are a code