473,396 Members | 1,927 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,396 software developers and data experts.

for loop question

hi..

basic foor/loop question..

i can do:

for a in foo
print a

if i want to do something like
for a, 2, foo
print foo

where go from 2, to foo..

i can't figure out how to accomplish this...

can someone point me to how/where this is demonstrated...

found plenty of google for for/loop.. just not this issue..

thanks

-bruce

Jul 6 '06 #1
4 1229
just do:

for a in range(2, foo+1):
print a

range(a, b) gives [a, a+1, a+2, ..., b-2, b-1]
bruce schrieb:
hi..

basic foor/loop question..

i can do:

for a in foo
print a

if i want to do something like
for a, 2, foo
print foo

where go from 2, to foo..

i can't figure out how to accomplish this...

can someone point me to how/where this is demonstrated...

found plenty of google for for/loop.. just not this issue..

thanks

-bruce
Jul 6 '06 #2
On 2006-07-06, Daniel Haus <da*********@gmail.comwrote:
>i can do:

for a in foo
print a

if i want to do something like
for a, 2, foo
print foo

where go from 2, to foo..
just do:

for a in range(2, foo+1):
print a
Except that in the OP's example foo was a sequence, not an
integer. I think.

--
Grant Edwards grante Yow! You can't hurt
at me!! I have an ASSUMABLE
visi.com MORTGAGE!!
Jul 6 '06 #3
Except that in the OP's example foo was a sequence, not an
integer. I think.
Yes, possibly. But then, what's "from 2 to foo"?

this way it might be

for a in [2] + foo:
print a

Jul 6 '06 #4
for a in range(2, len(foo)): print a

or maybe you need
for a in range(1, len(foo)): print a
?

York
bruce wrote:
hi..

basic foor/loop question..

i can do:

for a in foo
print a

if i want to do something like
for a, 2, foo
print foo

where go from 2, to foo..

i can't figure out how to accomplish this...

can someone point me to how/where this is demonstrated...

found plenty of google for for/loop.. just not this issue..

thanks

-bruce
Jul 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
0
by: John Wilson | last post by:
Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and stored procedure which takes @DemoID as input to match...
3
by: zeroDoNotYeSpamtype | last post by:
(I tried to post this earlier, but it seems without success) A similar question to this has been answered many times, to whit the question applying when the index variable of a for loop is...
3
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the...
22
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
3
by: nina297 | last post by:
Good morning, How do I set up a For each loop to loop through my records in the database? My fields are topics, question and answers. I want the one topic displayed that goes with each...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
2
by: perkykoala | last post by:
I apologize in advance for being REALLY detailed/verbose. It's the result of staring/tweaking code for too long. Using VB 2005: I need to design a multiple choice test (unfortunately, I can't...
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: 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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.