Type \\ at the prompt to exit q session. Inside a function, use value"\\\\" or exit 0 for the same result.
Note that the text following \\ and white space is ignored by q. This is often useful in scripts where \\ can be followed by comments or usage examples.
For a complete list of functions, see the kdb+ Function Reference.