# What is happening in this code? (A Tour of Go)

I’m working through “A Tour of Go” based on many recommendations. I’m a bit stuck on the slice of slices exercise. I’ve found the correct solution to the exercise but I would like to understand why my code times out. The first thing I don’t understand is where the values for `dx` and `dy` come from. I know from looking at the answer to the exercise that i had my x value and y value swapped but I don’t know what the actual values are.
Second, even if the values are swapped, I don’t see why it would cause the go playground (and the tour of go dialogue box) to time out. Both numbers (where ever they come from) are still finite.
Thanks in advance for the help!

EDIT: The solution I found is here: Tour of Go exercise #18: Slices - Stack Overflow

The dx and dy values are supplied by `pic.Show()`. This function sets dx and dy to 256.

For the second question, please share the code that times out, for better troubleshooting.

– Christoph

My apologies. I thought I shared the go playground link in my question. Here is my code that is timing out: Go Playground - The Go Programming Language

No Problem!

On a first glance, the loops do not seem to increase x and y. Maybe try the classic loop syntax: `for x := 0; x < dx; x++`

:facepalm:
Well that is more than slightly embarassing. I think i thought i was using the for-range form of those loops.
However, now that the code runs to completion, I’m not actually getting any patters (I’m currently trying (x ^ y) * (x ^ y) at the same go-playground link). Instead it’s just a blue square of one tone.

Any thoughts on that part?

Really? I get a nice tablecloth/dish towel pattern using this code:

Yeah so weird I switched to the standard for loop and it works but this code does not.

Ah! nevermind. I got it. I wasn’t resetting x to zero before the start of the inner loop.
Thank you for the help!

1 Like

Geez! I did not notice that, either!

“Pro” tip: Stick to the classic `for` syntax: `for <init>; <condition>; <update> {...}`.
It’s boring but less prone to bad surprises.