While..Do..While

While Loop එකකින් සිද්ද වෙන්නේ යම් condition එකක් false වෙනකන් අපි define කරපු statement එකක් repeatedly execute වෙන එක. එතකොට do..while? Do ..While එකකදී වෙන්නේ code block එකක් තුලින්  loop වෙලා ඊටපස්සේ repeat වෙන එක specify කරපු condition එකක් true වෙනකන්. මේ දෙකෙන්ම example කරලා බලමු.

While


Condition එක true වෙනව නම් විතරයි code block එක execute වෙන්නේ.

Output:
The Number is 1
The Number is 2
The Number is 3
The Number is 4
The Number is 5

Do...While

මෙතැනදී Do ඇතුලේ තියන code block එක execute උනාට පස්සේ තමයි condition එක true වෙනවද නැද්ද බලන්නේ.

Output:
The Number is 2
The Number is 3
The Number is 4
The Number is 5
The Number is 6