Check out example codes for "r while loop". It will help you in understanding the concepts better.

Code Example 1

# Basic syntax:
while (condition_is_true) {
  code to be repeated
}

# Example usage:
i = 1
while (i < 5) {	# True while i is less than 5
  print(i)
  i = i + 1		# Increment i each iteration
}

# Returns:
[1] 1
[1] 2
[1] 3
[1] 4

Code Example 2

while (test_expression)
{
statement
}

Learn ReactJs, React Native from akashmittal.com