Do While

This command is similar to While.
The main difference is that Do While checks the condition after it executes the block.
It executes the block at least once.

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

  • declare x: Integer
  • add a Do While command with condition x <= 0
  • input x in Do While body (arrow pointing from circle to Do While diamond)

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

Run the program and try various inputs: 1, 17, -55, 6.
It will finish the Do While only if you enter a positive number.

2 / 3