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

While LoopWhile Loop

A while loop is similar to a for-loop, however, it is used when we need to execute a block of code repeatedly based on a condition. The syntax of a while-loop is simpler than that of a for-loop:

Example:

cs

main.cs

The following diagram shows the execution process of a while loop:

Although the while loop may seem very similar to the for-loop at first, In more advanced levels of programming the difference becomes apparent. We might explore the usage of different kinds of loops in the Arrays section.

Tip: We can write true as the condition of a while-loop to create an infinite loop:

cs

main.cs

How many iterations will the following loop have?

Selecciona la respuesta correcta

¿Todo estuvo claro?

Sección 4. Capítulo 3
course content

Contenido del Curso

C# Basics

While LoopWhile Loop

A while loop is similar to a for-loop, however, it is used when we need to execute a block of code repeatedly based on a condition. The syntax of a while-loop is simpler than that of a for-loop:

Example:

cs

main.cs

The following diagram shows the execution process of a while loop:

Although the while loop may seem very similar to the for-loop at first, In more advanced levels of programming the difference becomes apparent. We might explore the usage of different kinds of loops in the Arrays section.

Tip: We can write true as the condition of a while-loop to create an infinite loop:

cs

main.cs

How many iterations will the following loop have?

Selecciona la respuesta correcta

¿Todo estuvo claro?

Sección 4. Capítulo 3
some-alt