Differentiate between while loop and do-while loop.

The while and do-while loops are similar in functionality, but they differ in the point at which the condition is tested:

While loop: The condition is evaluated before the loop body is executed. If the condition is false from the start, the loop body will not execute even once. Example:

int i = 0;
while(i < 5) {
printf(“%d\n”, i);
i++;
}

Do-while loop: The condition is evaluated after the loop body executes. This guarantees that the loop body will execute at least once, even if the condition is false initially. Example:

int i = 0;
do {
printf(“%d\n”, i);
i++;
} while(i < 5);