Add looping logic to your code using the do-while and while statements in C#

Beginner
Developer
Higher Education Educator
K-12 Educator
Student
.NET
Visual Studio Code

Use the do-while and while statements to iterate as long as a Boolean expression evaluates to true.

Learning objectives

After you complete this module, you'll be able to:

  • Write code that uses the do-while statement to iterate through a code block
  • Write code that uses the while statement to iterate through a code block
  • Use the continue statement to step directly to the Boolean evaluation

Prerequisites

  • Experience using Visual Studio Code to develop, build, and run C# console applications that include console I/O and access the methods of .NET classes
  • Experience using C# code to evaluate conditional expressions and manage variable scope inside and outside of code blocks
  • Experience using if-elseif-else and switch-case statements in C# to match a variable or expression against several possible outcomes
  • Experience using foreach and for statements in C# to loop through a block of code and access elements of array variables