Why do we not put a semicolon after repetition(except do-while) and selection structure? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why do we not put a semicolon after repetition(except do-while) and selection structure?

Why do we not put a semicolon after repetition(except do-while) and selection structure?

16th Oct 2017, 8:07 AM
Yusuf
Yusuf - avatar
1 Answer
+ 5
The {} block does it all. It stops the code after the function is over. Otherwise, the semicolon of the statement inside helps terminate the code after one iteration. The block is designed as such to terminate the code only when the function has finished execution. Thats why its available with only a few functions, inherited mostly from C. Although, even initializer lists of arrays require the semicolon after the {} block.
16th Oct 2017, 12:16 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar