Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP, C++, etc. syntax explanation

Why in the most programming languages required to put a semicolon after statements but not after things like if elseif and else?

Do the compilers all look out for newlines? If that's true then why wouldn't they do that for all statements?

Am I missing something? It really doesn't make sense to me...

like image 591
Mark Lalor Avatar asked Sep 09 '10 18:09

Mark Lalor


1 Answers

Usually the semicolon is required because the compilers ignore most whitespace. It's not needed after statements like if, elseif, else because it's not the end of the statement. Those are only complete statements when followed by a statement or block of statements.

like image 112
Colin Avatar answered Oct 05 '22 10:10

Colin