As I understand it, a square wave can be produced as follows:
$$y = \cases{ 1 & \text{if } \sin(x) > 0\cr 0 & \text{if }\sin(x) = 0\cr -1 & \text{if } \sin(x) < 0} $$
What I'm having trouble understanding are the vertical lines of the square wave, though. Aren't these supposed to be undefined, given that y can only be 1, 0, or -1? I must be missing something important, here.
The vertical lines are a consequence of the tradition of connecting points on graphs. The graph of a square wave should really be discontinued straight horizontal lines at two different y-coordinates, but that'd be difficult to look at. So we add in the vertical lines to make it look continuous.
Here's an example of a square wave. Note that if you remove the vertical lines from the image, you're left with what is still a square wave, but it's slightly harder to look at due to the discontinuities.