Best iteration method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kwm123
    New Member
    • Mar 2010
    • 4

    Best iteration method

    I have a minimum value, a maximum value and an increment index and I need to iterate between the minimum and maximum value by setting a variable 'val' to the minimum and then incrementing 'val' by adding increment index value to it till the maximum value is reached and then terminating it.

    I tried it initially with a for-loop but I am really ignorant at the moment on how best to do it.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    What it sounds like is that you really need to understand a for loop. The wikipedia article on a for loop should help you out a bit...



    I'd highly suggest taking a read through it.

    For C# though, a basic for loop can be broken down as such...

    Code:
    for (<variable> = <start value>; <condition for ending>; <increment>) { ... }
    The variable tells you what's controlling the loop and you can initialize it to a starting value. The condition for ending is generally a boolean logic test to see when the loop should finish. The increment is how much you want to change <variable> by on each iteration of the loop.

    Hopefully this helps you out a bit. A big tip for being new to programming is to try hitting google with your questions. There's tons of resources out there already that are readily available :)

    Also, Tlhintoq has a really helpful macro type thing he posts in threads from time to time on the best way to find help on various things, especially for the .NET library. Hopefully he wanders in here and can post it for you.
    Last edited by GaryTexmo; Mar 22 '10, 05:56 PM. Reason: formatting

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      I tried it initially with a for-loop but I am really ignorant at the moment on how best to do it.
      A for loop is exactly right. How about if you show us your code and we'll see if we can't help you clean up what you've written?

      Comment

      Working...