Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Do-While Loop | Loops
C# Basics

Do-While LoopDo-While Loop

The do-while loop is similar to the while-loop however it executes the specified code block first and then checks the condition hence it always executes the code block at least once even if the condition is false. Following is the syntax of the do-while loop:

Example:

cs

main.cs

The above code outputs "Hello World" even though the condition 1 < 0 is false. This will become more clear by looking at the flow diagram of the do-while loop:

How many iterations will the following loop have?

Selecione a resposta correta

Tudo estava claro?

Seção 4. Capítulo 4
course content

Conteúdo do Curso

C# Basics

Do-While LoopDo-While Loop

The do-while loop is similar to the while-loop however it executes the specified code block first and then checks the condition hence it always executes the code block at least once even if the condition is false. Following is the syntax of the do-while loop:

Example:

cs

main.cs

The above code outputs "Hello World" even though the condition 1 < 0 is false. This will become more clear by looking at the flow diagram of the do-while loop:

How many iterations will the following loop have?

Selecione a resposta correta

Tudo estava claro?

Seção 4. Capítulo 4
some-alt