Course Content

Course Content

FAQs

The while loop in Ruby is used to repeat a task until a certain expression is assessed as false.

There are three types of while loops.

  • Iterative loop: This type of loop continues to execute as long as the condition is true.
  • Conditional loop: This type of loop executes when the condition is true.
  • Infinite loop: This type of loop never ends and will continue to execute until a break statement is encountered or an exception occurs.

A while loop is a programming construct that allows code to be executed repeatedly until the expression evaluates to false. A do while loop is a programming construct that allows code to be executed repeatedly until the expression evaluates to true.

A while loop can be used to iterate over a list of items. For example, the following code will print out the numbers from 1 to 10:

  • var numbers = [1,2,3];
  • while (numbers.length > 0) {
  • console.log(numbers[0]);
  • numbers = numbers.slice(1);
  • }

The advantage of using a while loop is that it can be used when we need to execute a set of instructions repeatedly. This can be done in two ways: one is by incrementing or decrementing the value of the variable and checking for its equality with another value, and the other way is by checking for some event such as keyboard input.

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