loops

index in loop XSL

I have two nested loop in XSL like this, at this moment I use position() but it's not what I need. <xsl:for-each select="abc"> <xsl:for-each select="def"> I wanna my variable in here increasing fluently 1,2,3,4,5.....n not like 1,2,3,1,2,3 </xsl:for-each> </xsl:for-each> Can you give me some idea for this stub. Thank you very m...

c# Method looping and control.

Hi guys,I have a method that I would like to run over and over again.I would like to be able to start and stop this process. I have been using this pattern for some socket work and I am wondering what improvements I can make? public delegate void VoidMethod(); public class MethodLooper { private VoidMethod methodToLoop; privat...

How are local variables referenced in closures?

I am reading an article (JavaScript Closures for Dummies) and one of the examples is as follows. function buildList(list) { var result = []; for (var i = 0; i < list.length; i++) { var item = 'item' + list[i]; result.push( function() {alert(item + ' ' + list[i])} ); } return result; } function testList() { var fnlist ...

Performance difference in looping

Will there be a huge performance difference between: if (this.chkSelectAll.Checked) for (int i = 0; i < this.listBoxColumns.Items.Count; i++) this.listBoxColumns.SetSelected(i, true); else for (int i = 0; i < this.listBoxColumns.Items.Count; i++) this.listBoxColumns.SetSelected(i, false); vs. for (int i = 0; i...

Exists any alternative more beautiful at this loop?

$i=0; while ($row=mysql_fetch_assoc()) { if ($i==0) echo "First" $i++; } Access directly to mysqli pointer? a php class like's Iterator? Thanks. ...

PHP: How do you determine every Nth iteration of a loop?

I wanted to echo an image every after 3 post via XML here is my code : <?php // URL of the XML feed. $feed = 'test.xml'; // How many items do we want to display? //$display = 3; // Check our XML file exists if(!file_exists($feed)) { die('The XML file could not be found!'); } // First, open the XML file. $xml = simplexml_load_file($fee...

Python and subprocess

This is for a script I'm working on. It's supposed to run an .exe file for the loop below. (By the way not sure if it's visible but for el in ('90','52.6223',...) is outside the loop and makes a nested loop with the rest) I'm not sure if the ordering is correct or what not. Also when the .exe file is ran, it spits some stuff out and I ne...

Displaying array data in horizontal manner using php and smarty

Suggest me a better way to do it. I would like to show the array result in the horizontal manner. Column1 | Column 2 | Column 3 3 | 7 | 10 now it shows in vertical manner as follows Column1 | Column 2 | Column 3 3 7 10 Array Result : Stored in $result variable and assigned in ...

PHP Templating Looping Results

Hey! So here at work we have a home grown templating system, that is light weight and works great for us so far. The wall we're hitting is that we want to be able to loop over a template. The use case is something like search results. We are trying to think of ways that we could do this. We've come up with three ways right now. F...

C# Best way of assigning values to strings in a loop

Hi, I wonder what is the most efficient way of assigning string variables in a loop. So, for example if I have to browse through a list of nodes and assigning the value of the node to a string, would it be better if I define a variable before the loop starts like string myStringVariable = string.Empty foreach(XmlNode node in givenNodes)...

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...

Making a Next statement into a Loop statement in Visual Basic.

Hey everyone. My friend and I are re-learning Visual Basic, and we are stumped on this bit of code. For intAsterisks As Integer = 0 To intLine - 1 lblAsterisks.Text = lblAsterisks.Text + "*" Next We need to be able to make that from a For Next code into a Do Loop code. Could anyone assist us? ...

How to enumerate a list of non-string objects in Python?

There is a nice class Enum from enum, but it only works for strings. I'm currently using: for index in range(len(objects)): # do something with index and objects[index] I guess it's not the optimal solution due to the premature use of len. How is it possible to do it more efficiently? ...

Looping Through Set Number of Posts in Wordpress, Then running same loop again on next set, etc.

I have looked and looked and tried to find an answer for what I've been looking for, but I have yet to see an answer for this: I am trying to generate a Wordpress loop that takes all the posts from a single category and displays them three at a time inside <li></li> tags. Output should look like this: <li>My post title | Another Title...

Generate a periodic value based on dates

I was hoping someone that is good with math and loops could help me out. I'm writing a program in Objective C where I need to come up with a way to do a cycle. If you don't know Objective C I would appreciate any help in pseudo code just to help me figure this out. What I need is a scale that is based on two dates. I know this will be s...

how to loop through this array in php

I want to loop through this array: $securePages=array("admin.php","addslot.php","classpost.php"); $pagename="admin.php" Then if admin.php is found then execute this code: header("location:index.php"); exit(); How would I put together this looping statement? ...

Is there any overhead to declaring a variable within a loop? (C++)

I am just wondering if there would be any loss of speed or efficiency if you did something like this: int i = 0; while(i < 100) { int var = 4; i++; } which declares int var one hundred times. It seems to me like there would be, but I'm not sure. would it be more practical/faster to do this instead: int i = 0; int var; while(...

Loop in PLT Scheme

Hi, How can I implement loop in plt-scheme like in java- for(int i=0;i<10;){ for(int j=0;j<3;){ System.out.println(""+j); j++; } System.out.println(""+i); i++; } Thanks in advance. ...

Trigger to prevent infinite loop in a sql tree

I have node table with (NodeId, NodeName) and structure table (ParentNodeId, ChildNodeId). How can I write a trigger that check if an insert update or delete statement can cause infinite relation? ...

looping over columns in rails

This is probably very easy, but I'm having a hard time figuring it out. I have a partial: <% for room in @scrape %> <tr id="page_<%= room.id %>"> <th scope="row" class="<%= cycle("spec", "specalt") -%>"><%=h room.name %></td> <td class="<%=current_cycle%>"><%=h room.day1 %></td> <td class="<%=current_cycle%>"><%=h room.da...