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 678833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:11:35+00:00 2026-05-14T01:11:35+00:00

Is there a way of calling a method/lines of code multiple times not using

  • 0

Is there a way of calling a method/lines of code multiple times not using a for/foreach/while loop?

For example, if I were to use to for loop:

int numberOfIterations = 6;
for(int i = 0; i < numberOfIterations; i++)
{
   DoSomething();
   SomeProperty = true;
}

The lines of code I’m calling don’t use ‘i’ and in my opinion the whole loop declaration hides what I’m trying to do. This is the same for a foreach.

I was wondering if there’s a looping statement I can use that looks something like:

do(6)
{
   DoSomething();
   SomeProperty = true;
}

It’s really clear that I just want to execute that code 6 times and there’s no noise involving index instantiating and adding 1 to some arbitrary variable.

As a learning exercise I have written a static class and method:

Do.Multiple(int iterations, Action action)

Which works but scores very highly on the pretentious scale and I’m sure my peers wouldn’t approve.

I’m probably just being picky and a for loop is certainly the most recognisable, but as a learning point I was just wondering if there (cleaner) alternatives. Thanks.

(I’ve had a look at this thread, but it’s not quite the same)
Using IEnumerable without foreach loop

  • 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-05-14T01:11:36+00:00Added an answer on May 14, 2026 at 1:11 am

    Actually, the for loop does not hide what you’re trying to do.
    Anyone reading your code is already familiar with standard for loops and will understand instantly what you’re doing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to include php file using require and calling a php
tl;dr: No, there isn't a way. Calling publish_action using the JS SDK is actually
Let's say I have 10 threads running simultaneously. Is there any way of calling
Is there any way to clear parser buffers before calling YYACCEPT in yacc .
Is there a way in which I can detect the URL that is calling
Hi Is there any way to block my iPhone from calling/sending text to a
Is there any way to preserve spaces in a data.frame's column names when calling
Is there any difference in following two lines of code that compares the string
I know this isn't valid code, but is there a way to do something
Is there a way / I would like to know how to use a

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.