Quality Learning Support For Better Outcomes
First time here? Checkout the FAQs!
x
MathsGee is Zero-Rated (You do not need data to access) on: Telkom |Dimension Data | Rain | MWEB

1 like 0 dislike
124 views
What is the purpose of using Next statement in R language?
in Data Science & Statistics by Diamond (80,728 points) | 124 views

1 Answer

0 like 0 dislike
Best answer

A next statement is useful when we want to skip the current iteration of a loop without terminating it. On encountering next, the R parser skips further evaluation and starts next iteration of the loop.

The syntax of next statement is:

if (test_condition) {
next
}

Note: the next statement can also be used inside the  else branch of if...else statement.

Next statement

x <- 1:5
for (val in x) {
if (val == 3){
next
}
print(val)
}

Output

[1] 1
[1] 2
[1] 4
[1] 5

In the above example, we use the next statement inside a condition to check if the value is equal to 3.

If the value is equal to 3, the current evaluation stops (value is not printed) but the loop continues with the next iteration.

The output reflects this situation.

by Diamond (80,728 points)

Related questions

0 like 0 dislike
0 answers
1 like 0 dislike
1 answer
0 like 0 dislike
0 answers
asked Mar 12, 2019 in Data Science & Statistics by MathsGee Diamond (80,728 points) | 41 views
0 like 0 dislike
0 answers
0 like 0 dislike
0 answers
0 like 0 dislike
0 answers
asked Mar 11, 2019 in Data Science & Statistics by Edzai Zvobwo Bronze Status (8,642 points) | 41 views
0 like 0 dislike
0 answers
asked Mar 12, 2019 in Data Science & Statistics by MathsGee Diamond (80,728 points) | 32 views
0 like 0 dislike
0 answers
asked Mar 12, 2019 in Data Science & Statistics by MathsGee Diamond (80,728 points) | 36 views

Join the MathsGee Answer Hub community and get study support for success - MathsGee Answer Hub provides answers to subject-specific educational questions for improved outcomes.



On MathsGee Answers, you can:


  1. Ask questions
  2. Answer questions
  3. Comment on Answers
  4. Vote on Questions and Answers
  5. Donate to your favourite users
  6. Create/Take Live Video Lessons

Posting on MathsGee


  1. Remember the human
  2. Behave like you would in real life
  3. Look for the original source of content
  4. Search for duplicates before posting
  5. Read the community's rules
MathsGee Tools

Math Worksheet Generator

Math Algebra Solver

Trigonometry Simulations

Vectors Simulations

Matrix Arithmetic Simulations

Matrix Transformations Simulations

Quadratic Equations Simulations

Probability & Statistics Simulations

PHET Simulations

Visual Statistics

MathsGee ZOOM | eBook