From the course: Learning C#

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

While loops

While loops - C# Tutorial

From the course: Learning C#

While loops

- In a previous video, we learned about four loops which are usually used to execute a set of program statements for a set number of times. In this video we'll take a look at While loops, which are often used to execute statements for as long as a particular condition exists. So let's take a look at a simple example. So here in my While loops folder, I'll open up the code. So here in my code I have a string variable that I initialize to an empty string and I'm going to create a While loop using the while keyword. So I'm going to do that here and I'm going to write while, and then some parentheses and then the curly braces for my code. So inside the parentheses I need to define the logical expression that's going to be evaluated each time through the loop. So I'm going to have this loop execute while the input Str variable is not equal to the word exit. So I'm going to write while input Str is not equal to exit…

Contents