for-loop

Uses of 'for' in Java

I am fairly new to Java and in another Stack Overflow question about for loops an answer said that there was two uses of for in Java: for (int i = 0; i < N; i++) { } for (String a : anyIterable) { } I know the first use of for and have used it a lot, but I have never seen the second one. What is it used to do and when would I use it...

C++ delete from vector in for loop crash

Hi, I'm having a problem with my looping over a vector, and deleting values from another vector sometimes crashes my program. I have this vector of int's to keep track of which elements should be removed. std::vector<int> trEn; Then I loop through this vector: struct enemyStruct { float x, y, health, mhealth, speed, turnspeed; ...

C# List<> how to find last element

Hi, following is an extract from a code: public class AllIntegerIDs { public AllIntegerIDs() { m_MessageID = 0; m_MessageType = 0; m_ClassID = 0; m_CategoryID = 0; m_MessageText = null; } ~AllIntegerIDs() { } public void SetIntegerValues (int messageID...

Using break in nested loops

Hello everyone, Quick question, is it proper to use the break function to exit many nested for loops? If so, how would you go about doing this? Can you also control how many loops the break exits? Thanks, -Faken ...

In python is there an easier way to write 6 nested for loops?

This problem has been getting at me for a while now. Is there an easier way to write nested for loops in python? For example if my code went something like this: for y in range(3): for x in range(3): do_something() for y1 in range(3): for x1 in range(3): do_something_else() would there be an easier ...

cat/Xargs/command VS for/bash/command

The page 38 of the book Linux 101 Hacks suggests: cat url-list.txt | xargs wget –c I usually do: for i in `cat url-list.txt` do wget -c $i done Is there some thing, other than length, where the xargs-technique is superior to the old good for-loop-technique in bash? Added The C source code seems to have only one fork. ...

To convert PHP's while loop to a for -loop

How can you convert the following while loop to a for -loop in PHP? while( $row2 = pg_fetch_row( $result_tags ) While -loops are a source of errors for me. I see the while -loop as follows. for ( $i = 0 ; $i < count(pg_fetch_row( $result_tags )) ; $i++ ) ...

To convert foreach statements to for -loops in PHP

How can you convert foreach -statements to for -loops in PHP? Examples to be used in your answers 1 foreach( $end_array[1]['tags'] as $tag ) and 2 foreach($end_array as $question_id => $row2) ...

jQuery - .each() returning only the first element attributes, need to store each element attribute and use in each child element

I'm having headaches trying to make this work: I have a <a> element with a background-image defined with style="" attribute and I have put a function to append inside the <a> element a <span> handling different background-positions for :hover effects with opacity changes. The thing is, I need to get the same style attribute from each <a>...

For-loop in C++ using double breaking out one step early, boundary value not reached

I have a simple C++ program compiled using gcc 4.2.4 on 32-bit Ubuntu 8.04. It has a for-loop in which a double variable is incremented from zero to one with a certain step size. When the step size is 0.1, the behavior is what I expected. But when the step size is '0.05', the loop exits after 0.95. Can anyone tell me why this is happenin...

How does Python for loop work?

I am used to the C++ way of for loops, but the Python loops have left me confused. for party in feed.entry: print party.location.address.text Here party in feed.entry. What does it signify and how does it actually work? ...

Antcontrib <for> and <var unset="true"> in ant?

What versions of Antcontrib support <for> and also <var unset="true" /> in Antcontrib? (Or where can I go to find out that information?) ...

Why do some programming languages restrict you from editing the array you're looping through?

Pseudo-code: for each x in someArray { // possibly add an element to someArray } I forget the name of the exception this throws in some languages. I'm curious to know why some languages prohibit this use case, whereas other languages allow it. Are the allowing languages unsafe -- open to some pitfall? Or are the prohibiting...

What is the best way to check a ListView for checked Items in C#?

Hi! I'm writing a Database Editor / Bill of Materials Maker (2 separate .exe) for work, and I have this crazy issue. Here's how the flow works in the apps: Open Database, Search Database, Check Items Needed, Send to BOM Maker, Save as .xls. So far, I can send checked Items to the BOM Maker, but only if I open the search window, check t...

'for' loop and typecasting hell ! (PHP)

//matches[0] holds some preg_match'ed values for($i=0;$i<count($matches[0]);$i++) { $price = $matches[0][$i]; //a**uto type casting to (float) returns 0 for $price. Tried it for values greater than 1 too.** //echo gettype($price); $price = $price + 0.01; **//Returns 0 + 0.01 instead of the right answer** //**even after remov...

For each loop in vb.net

Hello, How do I use for loop in vb.net something like dim start as integer Dim customers as New List(Of Customers) Customers=dataAcess.GetCustomers() For each start=500 in Customers.count 'Do something here' Next I want to process some data for each 500 customers.. Please help ...

Batch file for loop statement

I've put together the batch file below; I don't have much experience with batch files and I can't figure out why the file fails with an error message stating that the: DO command was unexpected. Looking at the following code, does anyone know what I did wrong? Thanks. @ECHO OFF REM Set arguments supplied by Subversion SET REPOS ...

UIImageView not showing images with using for loop

hi I need to create around 50 uiimageview so that i am using a for loop for that and also assigning images for that view. its working fine with simulator but when i am running my application with device(iphone 3.0) it is not showing some images and some time its showing all the images, so that i am not able to find why its behaving such ...

Type limitation in loop variables in Java, C and C++

Why Java, C and C++ (maybe other languages also) do not allow more than one type on for-loop variables? For example: for (int i = 0; i < 15; i++) in this case we have a loop variable i, which is the loop counter. But I may want to have another variable which scope is limited to the loop, not to each iteration. For example: for (int ...

Batch file FOR/f expansion

I have a file (directories.txt) with directory names, each on a single line and I like to expand the line C:\Documents and Settings\%USERNAME%\My Documents In my script to the real user name running the script. However the echo comes out exactly the same as the line and %USERNAME% does not expand. FOR /f "tokens=*" %%X IN (directorie...