Do While

This command is like "While". The main difference is that "DoWhile" checks the condition after it executes the block. So we can say that it executes the code block at least once.

Let's write a program that reads a number from user. We want to make sure that it is positive:

We read it like this: "Enter number x, as long as it is less than or equal to zero"

You can run the program and try various inputs: 1, 17, -55, 6. It will finish the DoWhile only if you enter a positive number.

CodeExploreLearnLog In