Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:02:37+00:00 2026-06-17T06:02:37+00:00

I want to iterate a loop only for some values so I am using

  • 0

I want to iterate a loop only for some values so I am using this:

present <- c(3,5,7,8)
for(i in present)
{
   print(i)
}

which gives me

[1] 3
[1] 5
[1] 7
[1] 8

however I need to jump to the next value within the loop, say I dont want 5 to be printed in above example.

I cannot use next since I want it in nested for like this

present <- c(3,5,7,8)
for(i in present)
{
    k <- i
    "Jump to next value of present"
    while(k < "The next value for i should come here")
    {
        k <- k + 1
        print(k)
    }
}

The output would be 3 4 5 6 7 8 but the condition must check value of k if it exceeds next value of i.

Is there anyway to accomplish this?

I’ll take help of C to explain further,

for(i=0; i < 10; i++)
{
   for(k=i;k <= i+1;k++)
   {
       printf("%d", k);
   }
}

The link contains output of above code
http://codepad.org/relkenY3

It is easy in C since next value is in sequence, but here next value is not known, hence the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:02:38+00:00Added an answer on June 17, 2026 at 6:02 am

    What you should do is loop through two vectors:

    x <- head(present, -1)
    # [1] 3 5 7
    y <- tail(present, -1)
    # [1] 5 7 8
    

    and the function to do that is mapply (have a look at ?mapply). A close translation of your pseudo-code would be:

    invisible(mapply(function(x, y) while(x < y) {x <- x + 1; print(x)}, x, y))
    

    but maybe you’ll find this more interesting:

    mapply(seq, x + 1, y)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an .each loop in jQuery. I want to iterate the loop one
I want to create a loop that will iterate over several strings, but unable
I want to iterate through a table/view and then kick off some process (e.g.
const auto& would suffice if I want to perform read-only operations. However, I have
I have an array of random numbers. I want to change only some of
I want to iterate over a sequence in xquery and grab 2 elements at
I want to iterate through all 5 character combinations of 0-9, a-z. I worked
I want to iterate over an array of inputs that belong to certain class
I want to iterate over all childs of a jQuery's .children() return value, like
I want to iterate through store and make grid columns dynamically. When I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.