Quick question, what is the point for forcing the semicolon at the end of the while statement? See example below: Code: x = 0; do { x = x + 1; }while (x < 3); What's the point of having the semicolon after the (x < 3)? Why can't the compiler figure out that's the end of the while statement without the need for the semicolon? Thank you.
Thats a very interesting question and thought of answering the question as thats how its been designed but then thought about it and I came to this. All the lines in the code gets converted to assembly or some other intermediate langauge. Now when a while loop start line is something like Code: while (x < 3) but if we have the same thing in the do while loop i.e. without a semicolon there can be potential problems in while statements inside the do while loop. Compiler may become dependent on the braces { } to know if its start / End which is not also guarantee in statement having only one statements and so we dont have braces.