for-loop

Is there a value in using map() vs for?

Does map() iterate through the list like "for" would? Is there a value in using map vs for? If so, right now my code looks like this: for item in items: item.my_func() If it makes sense, I would like to make it map(). Is that possible? What is an example like? ...

for loop in window forms applications

Hello;-) I just designed a simple "For Loop" using window form application. I would like that this will be only clickable once & that it will not repeat the same information if I click the button. How could I do that? thanks Here is my code: int count; for (count = 0; count < 5; count = count + 1) { ...

Why is System/mscorlib code so much faster? Especially for loops?

This is just a personal project I've been digging into. Basically, I parse a text file (say from 20mb up to about 1gb) using StreamReader. The performance is pretty solid, but still... I've been itching to see what would happen if I parse it in binary. Don't misunderstand, I'm not prematurely optimizing. I am defintely micro-optimizing o...

Recursive file copy and rename on the Vista command line

I'm trying to recurse through my music directory and copy every file called folder.jpg to a file in the same directory called cover.jpg. I've tried variations of suggestions in this question such as this: for /r %i in (folder.jpg) do copy %i cover.jpg Resulting in "The system cannot find the file specified." How can solve this probl...

For Loop runs thru twice

Can someone tell me why this processes all the files and then does it again? Its driving me crazy. Thanks private void HP3BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker hp3worker = (BackgroundWorker) sender; DirectoryInfo hp3Files = new DirectoryInfo(fromPath + @"\hp3\"); Fi...

Transact-SQL: insert into xyz ( select * from abc )

Hi, i want to realize a construct in MS SQL that would look like this in Oracles PL/SQL: declare asdf number; begin for r in (select * from xyz) loop insert into abc (column1, column2, column3) values (r.asdf, r.vcxvc, r.dffgdfg) returning id into asdf; update xyz set column10 = asdf where ID = r.ID; end loop; end; Any i...

Thoughts on foreach with Enumerable.Range vs traditional for loop

In C# 3.0, I'm liking this style: // Write the numbers 1 thru 7 foreach( int index in Enumerable.Range( 1, 7 ) ) { Console.WriteLine( index ); } over the traditional for loop: // Write the numbers 1 thru 7 for( int index = 1; index <= 7; index++ ) { Console.WriteLine( index ); } Assuming 'n' is small so performance is not a...

why isn't this php loop working?!

I have this code: $thisTime = gmmktime(0, 0, 0); for($i=0; $i<=95; $i++) { $perfTimeNumber = ($i+1); $perfTimestamp = $thisTime; $perfTime = date("H:i", $perfTimestamp); echo '<option value="'. $perfTimeNumber .'" selected="'.$sel.'">' .$pe...

batch for loop with bracket in the command

I have a batch file with the following code: for /f "tokens=*" %%a in ('dir /b /a-d') do ( echo Processing %%a >>%LOG% dtsrun /S(local) /NNotesLoad /A"FilePath:8="%NOTESDIR%\%%a" /AClientID=%1 >>%LOG% echo Deleting %%a >>%LOG% del %%a /q ) This is returning an error message of "/NNotesLoad was unexpected at this time" because the...

For loop missing several indexes with segfault

The output of the application (bottom) is as follows: Element index number: 0 Element contents: 22 Element index number: 1 Element contents: 22 Element index number: 2 Element contents: 22 Element index number: 3 Element contents: 22 Element index number: 4 Element contents: 22 Element index number: 22 Element contents: 134513712 Why...

Is it possible to do a For...Each Loop Backwards?

I don't believe this is possible by conventional methods, but something like this verbose code: For Each s As String In myStringList Step -1 //' Do stuff here Next I will probably have to invert the myString object before a conventional For..Each Loop, correct? ...

django: second for loop produces no elements

I'm fetching a recordset, and doing a for loop to display the data like so: {% for category in categories %} {"img":"{{ category.pr_image }}", "url":"{{ category.pr_store_url }}", "type":"ca", "price":"{{ category.pr_price }}", "store":"{{ category.pr_store }}", "name":"{{ category.pr_name }}", "lat":"{...

Why am I getting a NullPointerException in this for loop?

here is my code: Comic[] comix = new Comic[3]; comix[0] = new Comic("The Amazing Spider-man","A-1","Very Fine",9240.00F); comix[0].setPrice((Float)quality.get(comix[0].condition)); for(int i=0;i<comix.length;i++){ System.out.println("Title: " + comix[i].title); } Why am I getting a NullPointerException when this code run...

Collection Values Changing in for loop

I've got a bit of code that I've been working on for a friend for the past few days. At a high level it parses a text file and writes to an MDB. To cut a long story short, I've got a nested couple of loops doing some processing on the items. The inner loop only gets called in certain cases, but when it does, it's doing some strange th...

concurrently iterating through even and odd items of list

I have a list of items (which are HTML table rows, extracted with Beautiful Soup) and I need to iterate over the list and get even and odd elements (I mean index) for each loop run. My code looks like this: for top, bottom in izip(table[::2], table[1::2]): #do something with top #do something else with bottom How to make this...

CMD For Loop does not hold set /a value

Didn't know how to explain this well, so here is the code @echo off set test=0 for /f %%a in (textfile.txt) do ( rem loops five times(5 lines in textfile.txt) set /a test=test+1 rem Adds 1 to Test echo %%a rem Echo's correct line in file echo %test% rem Echo's whatever X was before the loop ) echo %test% rem Displays the correct v...

file won't write in python

I'm trying to replace a string in all the files within the current directory. for some reason, my temp file ends up blank. It seems my .write isn't working because the secondfile was declared outside its scope maybe? I'm new to python, so still climbing the learning curve...thanks! edit: I'm aware my tempfile isn't being copied current...

Getting the first and last item in a python for loop

Is there an elegant and pythonic way to trap the first and last item in a for loop which is iterating over a generator? from calendar import Calendar cal = Calendar(6) month_dates = cal.itermonthdates(year, month) for date in month_dates: if (is first item): # this is fake month_start = date if (is last item): ...

django for loop counter break

This is hopefully a quick/easy one. I know a way to work around this via a custom template tag, but I was curious if there were other methods I was over looking. I've created a gallery function of sorts for my blog, and I have a gallery list page that paginates all my galleries. Now, I don't want to show all the photos of each gallery in...

ASP.Net: Tight loop In presentation layer

For a single web request, We fetch more than 1000 rows of data from an external system and we need to re-format the data into much better presentation format before we display it to the end user on the web page. When we loop through the data in ASPX pages, it is creating a hard loop (or tight loop?) which is consuming more than 95% of ...