TEDSF Interview Skills Q&A Platform
1 like 0 dislike
62 views
What is the purpose of using Next statement in R language?
in Data Science by Platinum (104k points) | 62 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 Platinum (104k points)

Related questions

0 like 0 dislike
0 answers
asked Sep 1, 2019 in Web Development by TEDSF Platinum (104k points) | 8 views
0 like 0 dislike
0 answers
asked May 3, 2019 in Data Science by TEDSF Platinum (104k points) | 5 views
0 like 0 dislike
0 answers
asked Mar 5, 2019 in Grade 3 Maths by TEDSF Platinum (104k points) | 16 views
Welcome to TEDSF Skills Questions and Answers, a platform, where you can ask skills questions and receive answers from other members of the community. On TEDSF the youth, students, teachers, policy makers and enthusiasts can ask and answer any questions. Get help and answers to any skills-related problem including mathematics, computer science, data science, web development, physics, chemistry, digital marketing, African development and more. Help is always 100% free!

4.1k questions

1.4k answers

64 comments

29.6k users

4,058 questions
1,448 answers
64 comments
29,583 users