+ 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.
1 Antwort
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)