473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Best iteration method

4
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.
Mar 22 '10 #1
2 2233
GaryTexmo
1,501 Expert 1GB
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...

http://en.wikipedia.org/wiki/For_loop

I'd highly suggest taking a read through it.

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

Expand|Select|Wrap|Line Numbers
  1. 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.
Mar 22 '10 #2
tlhintoq
3,525 Expert 2GB
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?
Mar 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Franck Bui-Huu | last post by:
Hello, I'm trying to customize a list by overriding __getitem__ method but this change seems to not work with for iteration. When I use my customized list in a for iteration, all changes made...
35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
10
by: Florian Lindner | last post by:
Hi! If I iterate through a list, is there a way I can get the number of the iteration: first, second, third, ... l = for x in l print x print x.iteration() # <- That's what I'm looking for!...
4
by: Johannes Hansen | last post by:
What are the best practice on handling an exception caused by a Dispose method when its called from inside a loop? Wrap the entire loop in a try-catch or do the try-catch on each iteration to get...
5
by: Ant | last post by:
hi, I'm now using C#. Seeing as though you can declare & initialize or pass a value to a variable on the same line as the declaration, is it still best practice to group all the variables together...
45
by: Summercoolness | last post by:
it seems that range() can be really slow: the following program will run, and the last line shows how long it ran for: import time startTime = time.time() a = 1.0
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
9
by: news.microsoft.com | last post by:
I am looping through an iteration and I would like to test the next item but if its not the one that I want how do I put it back so that when my foreach continues it is in the next iteration? ...
23
by: Florian Lindner | last post by:
Hello, can I determine somehow if the iteration on a list of values is the last iteration? Example: for i in : if last_iteration: print i*i else:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.