while Loops

In this lesson, we will learn all about the while loop in R language.

The simplest kind of loop in the R language is the while loop.

It is simply translated as: "if the given condition is satisfied then execute the statements in the while block and if the condition is not satisfied break the loop (which means the block of code in the curly brackets { } will not be executed).

Syntax of a while loop

The syntax for while loop in R:

while(condition)
{
  statements
}

Let’s take an example of while loop.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy