inner value 2 :
x = 15, y = 24 , x = 18
inner value 1 : ( the for loop break )
x = 18 and y= 22
outer =1 :
inner = 4, x = 24, y = 20 ,
inner = 3 , x = 30 , y =18
inner = 2 , x = 36, y = 16
inner = 1 ( won't executed )
exits inner for loop
x = 36, y = 14
outer= 2 ;
inner = 4 :
x = 42, y = 12
inner = 3 :
x = 48 , y = 10 ;
inner =2
x = 54, y = 8
inner =1 : exits inner for loop
x = 54 and y = 6
thus the final values are x = 54, and y = 6 only
:
What I am curious about at this point is will the program will start the if statement right away as soon as x reaches 6?
-> The program will then run for integer inner value 3 , then x becomes 9 and y becomes 26 . x != 6 , if condition wont be executed then x becomes 12
inner value 2 :
x = 15, y = 24 , x = 18
inner value 1 : ( the for loop break )
x = 18 and y= 22
outer =1 :
inner = 4, x = 24, y = 20 ,
inner = 3 , x = 30 , y =18
inner = 2 , x = 36, y = 16
inner = 1 ( won't executed )
exits inner for loop
x = 36, y = 14
outer= 2 ;
inner = 4 :
x = 42, y = 12
inner = 3 :
x = 48 , y = 10 ;
inner =2
x = 54, y = 8
inner =1 : exits inner for loop
x = 54 and y = 6
thus the final values are x = 54, and y = 6 only
The if statement will never be true so we can ignore it, the inner loop runs a total of 9 times where you add 6 each time -> 9*6=54=x and substract 2 9 times = 18, outer loop runs 3 times total where you also substract 2 = 6. y=30-18-6=6. Not sure where your 42 comes from but for clarification just set some breakpoints and let it play through in the debugger
发布评论
评论(2)
- >然后,该程序将用于整数内值3,
然后x变为9,y变为26。 x!= 6,如果无法执行条件,则x变为12
:
-> The program will then run for integer inner value 3 ,
then x becomes 9 and y becomes 26 . x != 6 , if condition wont be executed then x becomes 12
:
if语句永远不会是正确的,因此我们可以忽略它,内部循环总共运行9次,每次添加6次 - > 9*6 = 54 = x
并提取2 9次= 18,外循环总共运行3倍,您还可以提取2 = 6。y = 30-18-6 = 6。不确定您的42来自何处,但为了澄清,请设置一些断点,然后在调试器中播放
The if statement will never be true so we can ignore it, the inner loop runs a total of 9 times where you add 6 each time -> 9*6=54=x
and substract 2 9 times = 18, outer loop runs 3 times total where you also substract 2 = 6. y=30-18-6=6. Not sure where your 42 comes from but for clarification just set some breakpoints and let it play through in the debugger