Do while loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Do while loop

why to we use semicolon after the while statement in do while loop but we don't use semicolon after while statement in while loop

25th Aug 2018, 12:27 AM
Hemanth Kumar
Hemanth Kumar - avatar
2 Answers
+ 1
Since the } isn't the end, then it helps to have some way to know that the end of the statement is reached, hence the semi-colon. It is possible to write a language without it, but it makes more sense to require it, in these languages
25th Aug 2018, 11:24 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Hemanth kumar it is syntax and one has to follow it based on language we are using... one reason might be as below: while loop starts with condition... if you place semicolon there, it doesn't understand that code block in braces are to be considered as loop statement..while loop statement consider semicolon as end of loop statement... where as in case of di while loop, while is at the end after code block.. to let compiler know about end of loop is accomplished by semicolon..
25th Aug 2018, 1:47 AM
Ketan Lalcheta
Ketan Lalcheta - avatar