Go through it on paper, or line by line in a debugger
var x=0
So x is 0
for(outer in 1..3)
everything in this for will loop with outer being 1 then 2 then 3. So for the first pass outer is 1;
x = 0
outer = 1
for(inner in 4 downTo 2)
this will loop with inner being 4, 3, 2
x = 0
outer = 1
inner = 4
x+=6
x = x + 6, as x was 0 it is now six
x = 6
outer = 1
inner = 4
x+=3
Same thing, so now x is 9
x = 9
outer = 1
inner = 4
That's the "inner" loop finished so it runs again only now inner is 3
x = 9
outer = 1
inner = 3
x+=6
x = 15
outer = 1
inner = 3
x+=3
x = 18
outer = 1
inner = 3
and so on. Follow the maths and you'll see why you get the results you do.