Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Next loop - Receiving error

Tags:

loops

for-loop

r

I have tried the following simple for next loop in R programming:

for(i in 1:100)  { if(i <= 20)  {  next  } print(i) }

Below is the error message I am receiving:

Error: unexpected symbol in "for(i in 1:100) { if(i <= 20) {next} print"

Please help me understand why I am receiving the error.

like image 708
Chak K Avatar asked Dec 13 '25 22:12

Chak K


1 Answers

Give this a shot:

for (i in 1:100) { 
  if (i<=20) {
    next
  };
  print(i)
}

Looks like you missed your semi-colon. You need this to denote the end of a statement.

like image 95
theamateurdataanalyst Avatar answered Dec 15 '25 11:12

theamateurdataanalyst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!