for-loop

How do you find the last loop in a For Each (VB.NET)?

How can I determine if I'm in the final loop of a For Each statement in VB.NET? ...

Whats The Most Efficient Way To Instantiate Worker Variables

Should I instantiate my worker variables inside or outside my for loop E.g. a) bool b = default(bool); for (int i = 0; i < MyCollection.Length; i++) { b = false; foreach(object myObject in myObjectCollection) { if (object.Property == MyCollection[i].Property) { b = true; break; } } if (b) {...

Replace string characters from array.

I have a string (of undertermined length) that I want to copy a lot of times replacing one character at a time from an array (of undertermined length) of characters. So say I have this string: 'aa' And this array: ['a', 'b', 'c', 'd'] after some magic for-looping stuff there would be an array like: ['aa', 'ab', 'ac', 'ad', 'ba', 'bb'...

Is there a hidden iteration counter in this for loop?

If you have a for loop such as: For Each s As String In stringList ..do stuff.. Next is there some sort of (hidden) iterator or do I have to add an external integer to keep count: Dim i As Integer For Each s As String In stringList ..do stuff.. i += 1 Next ...

Is there any way to do n-level nested loops in Java?

In other words, can I do something like for() { for { for { } } } Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another? Of course, the idea is that there should be an "easy" or "the usua...

Are there alternative methods for saying 'next' in a pl/sql for loop?

So I've got a for loop that processes a list of IDs and has some fairly complex things to do. Without going into all the ugly details, basically this: DECLARE l_selected APEX_APPLICATION_GLOBAL.VC_ARR2; ...snip... BEGIN -- get the list ids l_selected := APEX_UTIL.STRING_TO_TABLE(:P4_SELECT_LIST); ...

mocking superclass protected variable using jmockit

Hi, I couldnt able to mock the protected varibale defined in the superclass.i could able to mock the protected method in superclass but couldnt to mock the protected variable in to the subclass ,wherein am writing the testcase for subclass,Please if anybody out there has any soluton for it .please reply. Thanks Shashi ...

Python classes from a for loop

I've got a piece of code which contains a for loop to draw things from an XML file; for evoNode in node.getElementsByTagName('evolution'): evoName = getText(evoNode.getElementsByTagName( "type")[0].childNodes) evoId = getText(evoNode.getElementsByTagName( "typeid")[0].childNodes) evoLevel = get...

python, index errors

I've got some code which draws data from an xml file but it seems to have randomly starting throwing; Traceback (most recent call last): File "C:\Users\mike\Documents\python\arl xml\turn 24 reader", line 52, in <module> unitCount = getText(evoNode.getElementsByTagName("count")[0].childNodes) IndexError: list index out of range ...

In XSLT how do I access elements from the outer loop from within nested loops?

I have nested xsl:for loops: <xsl:for-each select="/Root/A"> <xsl:for-each select="/Root/B"> <!-- Code --> </xsl:for> </xsl:for> From within the inner loop, how can I access attributes from the current node in the outer loop? I keep finding myself writing code like this: <xsl:for-each select="/Root/A"> <xsl:varia...

Don't monkey with the loop index

One of Steve McConnell's checklist items (pdf) is that you should not monkey with the loop index. This makes intuitive sense and is a practice I've always followed except maybe as I learned how to program back in the day. In a recent code review I found this awkward loop and immediately flagged it as suspect. for ( int i=0 ...

Is there a way to access an iteration-counter in Java's for-each loop?

Is there a way in Java's for-each loop for(String s : stringArray) { doSomethingWith(s); } to find out how often the loop has already been processed? Aside from using using the old and well-known for(int i=0;i<boundary;i++)-loop, is the construct int i = 0; for(String s : stringArray) { doSomethingWith(s); i++; } the only wa...

Replace Nested For Loops... or not

I have a script that loops through a series of four (or less) characters strings. For example: aaaa aaab aaac aaad If have been able to implement it with nested for loops like so: chars = string.digits + string.uppercase + string.lowercase for a in chars: print '%s' % a for b in chars: print '%s%s' % (a, b) ...

How to write the sequence 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 in JAVA ?

I'm currently beginning to program with Java. I tried to code the sequence in the title as an output in Java, but I'm stuck! I'm experimenting with the for function, any help is welcomed ;) ...

Project Euler #5 php doubt!!!

problem euler #5 i found the solution but i don't know why this first code is faster (i put 14 in order to try to make more clear the code) the only difference is that i eliminate the for i wrote for a huge if if($num%14==0 && $num%13==0 &&$num%12==0 &&$num%11==0 &&$num%10==0 && $num%9==0 && $num%8==0 && $num%7==0 && $num%6==0 && $num%...

Multiple ways to move through an Iterator

Hi, When I use an Iterator of Object I use a while loop (as written in every book learning Java, as Thinking in Java of Bruce Eckel): Iterator it=... while(it.hasNext()){ //... } but sometime i saw than instead somebody use the for loop: Iterator it=... for (Iterator it=...; it.hasNext();;){ //... } I dont' understand this...

How to calculate the number of operations that occur during the execution of a for loop?

I had an exam a couple of days ago and today the Instructor gave us the key answer of the exam. One of the questions was for ( j = 9; j >= 1; j-- ) Count the Number of operations The result was 20. Can anyone explain how he gets 20 operations from that? ...

Does the termination condition of a 'for loop' refresh in VC++ 6?

for (int i = 0 ; i < stlVector.size() ; i++) { if (i == 10) { stlVector.erase(stlVector.begin() + 5 ) } } Does the termination condition part "stlVector.size()" take "stlVector.erase(...)" into consideration? In other word does stlVector.size() refresh for every loop iteration? I can't test it right now, so i post...

For (loop) dynamic creation in as3

Hello! I'm trying to create dynamic balls by using for loop. For some reason I get two objects (trace show 2 balls and their DIFFERENT properties), but on the stage I can see just a last one created. This is my code: var randomBall_mc:ball=new ball(); for (i=1; i<3; i++) { addChild(randomBall_mc); randomBall_mc.name="rando...

How handle an exception in a loop and keep iterating?

I need a for loop which will complete all its Iterations even if there's any exception in any one of the iterations. ...