Lesson #8 - While and DoWhile loops

Updated: Dec 13, 2020

In c# we have different types of loops that we can use as part of writing our program. Loops are used to execute a part of code as long as a specified condition is reached.

The use of loops is very common has it has many advantages:

  • They most definitely save time (by reducing multiple code lines).

  • They help to make code more readable and improve its clarity.

  • Due to their simple logic, they also help to reduce code errors.

While loop

DoWhile loop

The doWhile loop is similar to the while loop but with one major difference. This loop will execute the code block once, before checking the result of the condition, then it works as we saw in the previous loop (Will run as long as the condition return ‘true’).



4 views0 comments