# semi-colon in q scripts

**URL:** <https://forum.kx.com/t/semi-colon-in-q-scripts/14233>\
**Category:** Community Support\
**Tags:** imported, kdb-and-q\
**Created:** [May 31, 2025, 11:05am UTC](https://forum.kx.com/t/semi-colon-in-q-scripts/14233 "2025-05-31T11:05:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dang30.swati](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/dang30.swati/32/128_2.png) [@dang30.swati](https://forum.kx.com/u/dang30.swati)\
**Post date:** [May 31, 2025, 11:05am UTC](https://forum.kx.com/t/semi-colon-in-q-scripts/14233/1 "2025-05-31T11:05:05Z")

</div>

[https://learninghub.kx.com/forums/topic/semi-colon-in-q-scripts](https://learninghub.kx.com/forums/topic/semi-colon-in-q-scripts)

when is semi-colon needed in the q script and when is it not? thanks! I thought it's needed everywhere but my script doesn't error out  
.ns.a:1;  
.ns.b:2 //no semi-colon  
.ns.c:3;

---

<div class="post-metadata">

**Author:** ![unterrainer\_ale](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/unterrainer_ale/32/108_2.png) [@unterrainer\_ale](https://forum.kx.com/u/unterrainer_ale)\
**Post date:** [May 31, 2025, 1:28pm UTC](https://forum.kx.com/t/semi-colon-in-q-scripts/14233/2 "2025-05-31T13:28:20Z")

</div>

Generally speaking each new line is a new statement (Note this is not valid inside a lambda and you need a trailing semicolon to separate expressions). You can use semicolons to separate expressions.

https://github.com/qbists/style/blob/main/semicolons.md

&nbsp;A good article to read is Stephen Taylor's "Remarks on Style" https://github.com/qbists/style/tree/main

Personally, I prefer to use semicolons always when separating expressions

---

<div class="post-metadata">

**Author:** ![dang30.swati](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/dang30.swati/32/128_2.png) [@dang30.swati](https://forum.kx.com/u/dang30.swati)\
**Post date:** [June 1, 2025, 8:35am UTC](https://forum.kx.com/t/semi-colon-in-q-scripts/14233/3 "2025-06-01T08:35:51Z")

</div>

thank you, when are semi-colons necessary in q script? just at the end of function defintions?

---

<div class="post-metadata">

**Author:** ![pgyorok](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/pgyorok/32/128_2.png) [@pgyorok](https://forum.kx.com/u/pgyorok)\
**Post date:** [June 2, 2025, 9:40am UTC](https://forum.kx.com/t/semi-colon-in-q-scripts/14233/4 "2025-06-02T09:40:55Z")

</div>

When you load a script using \l, it is broken into blocks using a set of rules involving indentation and comments. Each block is then evaluated separately. A block doesn't have to end in a semicolon, so if you have multiple unindented lines in a sequence, each of them will be its own block and not need a semicolon. However if you indent some of the lines (which is required for a multiline lambda), those become part of the same block with the previous non-indented line, so semicolons are necessary to separate the individual statements in the block.

Another important factor is that IPC doesn't do the same block splitting, so if you use a tool such as KDB Studio, it will execute the entire code as a single block, therefore any missing semicolons could result in errors due to the different lines running together. For this reason I prefer to put a semicolon after every statement. Another benefit is that this prevents garbage from being printed on the console when loading the file.
