---
schema_version: "1"
id: db2632ef28daad81efce51278734af0057230509dca158461172538bcde1c873
title: Do-While Loops
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/langCon_apex_loops_do_while.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_do_while.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6e4eed35c5311e992cd07f3318e02cdbf2b5af75680d4932b696ae094b6fdccf
---
# Do-While Loops

The Apex do\-while loop repeatedly executes a block of code as long as a particular Boolean condition remains true. In this syntax, code\_block is a placeholder value. The syntax is:

do {
   code\_block
} while (condition);

![Note](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/images/icon_note.png)

#### Note

Curly braces ({}) are always required around a code\_block.

As in Java, the Apex do\-while loop does not check the Boolean condition statement until after the first loop is executed. Consequently, the code block always runs at least once.

As an example, the following code outputs the numbers 1–10 into the debug log:

Integer count = 1;

do {
    System.debug(count);
    count++;
} while (count < 11);

- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_while.htm "While Loops")