Why the semicolon | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why the semicolon

I understand coding is essentially logic on a computer level, but what catches me is: Why is it in MOST programming languages, a statement MUST end with ; This particular “small thing” I don’t understand cant the computer recognise say Var up=up instead of var up=up;(this is just for an example) Would just like to have some understanding of why the semicolon is needed to end a logical statement.

27th Sep 2018, 11:46 AM
IDGam3r
IDGam3r - avatar
1 Answer
0
Well like you said it's most programming languages but not all (e.g. Python). The only thing to understand is : it is convention. You definitely need something so that the compiler knows it is the end of a statement. But you need it to be something that is not too commonly used. Why not just have end of line as end of statement : well Python does it (and goes even further removing brackets and such to only use indentation to specify nesting). But what if you need your statement to go on multiple lines (for readability for example) and you want the newline to be the continuation of the statement? Well in Python you need to put a \, in other languages using the semi-colon ; to end statements you need not do anything... What if you want to put multiple statements in one line ? In Python you're limited to what the compiler can understand. EDIT : About the end of line as end of statement, also think about the time where UI was not the way it is today and code practices were very diverse among coders (some might skip lines, other might never indent)
27th Sep 2018, 11:56 AM
dhm