while statement:
var i = 1;
while(i<10)
{
document.write(i);
i ;
}
do while statement:
var i = 1;
do
{
document.write(i);
i ;
}while(i<10);
From the above example, let’s analyze their two points Difference:
1. Because the while statement always detects the loop expression first, its loop body may not be executed once; while the do/while statement detects the loop expression at the bottom of the loop, so its loop The body will be executed at least once.
2. A semicolon should be added at the end of the do/while statement. This is because it ends with a loop condition instead of simply using curly braces to mark the end of the loop body.