Course Content

Course Content

FAQs

A while loop is a conditional statement that executes a block of code while a condition is true.

The following example shows how to use the while loop in C Sharp:

  • int x = 0; int y = 0; int z = 0;
  • while(x< 10) {
  • y++;
  • z++;
  • }

The first thing you need to do is to create an infinite loop by adding a semicolon after the condition and then write your code inside it. Then, add the keyword break statement outside of your infinite loop followed by a return statement. This will stop executing your code inside the infinite loop and return execution back to where you started with your infinite loop's body.

The benefits of using while loops are numerous. It can help you write more readable code and save time by preventing the need for nested if-else statements.

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
Apple App Store
598K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
15K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere