loops

Loop through two dimensional array with Smarty

Hey guys, I am trying to make the following loop work. Basically, I am trying to display the children as options. Why doesn't it work? The optiongroups are being displayed. And the arrays are constructed the right way. {foreach from=$tpl_parents item='row' key='i'} <optgroup label="{$row.NAME}"> {foreach from=$tpl_children....

SQL Server query - loop question

I'm trying to create a query that would generate a cross-check table with about 40 custom columns that show Y or N. Right now I have SELECT DISTINCT [Company], [Option1], [Option2], [Option3], CASE WHEN [Table1].[ID1] IN (SELECT ID2 FROM Table2 WHERE Variable = 1 AND Bit = 1) THEN ...

Parsing nested structures in PHP with preg_match

Hello I want to make something like a meta language which gets parsed and cached to be more performant. So I need to be able to parse the meta code into objects or arrays. Startidentifier: { Endidentifier: } You can navigate through objects with a dot(.) but you can also do arithmetic/logic/relational operations. Here is an example o...

What is the most appropriate sentinel method?

What is the most appropriate sentinel method? This breaks out of an infinite loop: infinite loop read in a value; if (value == Sentinel) then exit; process the value; This uses duplicate code: read in a value; while (value != Sentinel) process the value; read in a value; This uses a boolean variable i...

Finding the product of a variable number of Ruby arrays

I'm looking to find all combinations of single items from a variable number of arrays. How do I do this in Ruby? Given two arrays, I can use Array.product like this: groups = [] groups[0] = ["hello", "goodbye"] groups[1] = ["world", "everyone"] combinations = groups[0].product(groups[1]) puts combinations.inspect # [["hello", "world...

Object reference not set to an instance of an object with a class with an array of classes as a member

Here is the structure that I have: Friend Class StandardFormatFile Friend fileType As String Friend numberOfSeries As Integer Friend standardSeriesData As New ArrayList End Class Friend Class StandardFormatFileSeries Friend standardNumOfElements As Integer Friend standardSeriesName As String Friend standardDat...

Cocoa Touch - Looping Help

I need help with some programming logic... I need to loop this method to display the math problem in my labels then sleep(5) and then loop again. Anything I've tried ends of freezing the program. PLEASE help! I've been tearing my hair out trying everything I know! EDIT: I edited the code to this, After 3 seconds it fades away the label ...

how to optimize looped searching in R?

I am trying to scan a dataset using a loop in R, to see if the data points in the subset of data fulfill some rules, an example is pasted here: loop.ward <- 1 loop.control.chart <- 1 while (loop.ward <= length(unique(control.chart[,"ward"]))) { loop.weekly.count <- 3 while (loop.weekly.count <= nrow(control.chart[control.chart[,"w...

Deeper understanding on loops (for, while, do while, foreach, recursion, etc.)

If givin some situation that you can do a loop of a certain event or function that needed to be solved using loops, where you can achieve these by any kind of loop. How can we determine the difference between each loops that can be used based on their speed, efficiency, and memory usage? Like for example, you have these loops for(int...

Looping through controls in WPF / Powershell

I am trying to loop through some controls in a Powershell / WPF application. Nothing fancy, just setting some text on a mouseEnter event. It works fine if I don't loop the code: $reader = New-Object System.Xml.XmlNodeReader $xaml $d = [Windows.Markup.XamlReader]::Load($reader) $d.FindName("GridOne").add_mouseEnter({ $d.Find...

Looping a RECORDSET

I have a webservice that returns me a recordset. The record set looks something like this. COUNTRYNAME STATEPROVINCE POPULATION CANADA ALBERTA 2.7 million CANADA NOVA SCOTIA 1.6 million UNITED STATES PENNSYLVANIA 4.5 million UNITED STATES NEW JERSEY 6.8 million This ...

Make nested for loop algorithm - dynamic

I have an algorithm that goes something like this: for m = 1 to 2 initialize(work_item(m)) for l = 1 to 2 initialize(work_item(l)) for k = 1 to 2 initialize(work_item(k)) for j = 1 to 2 initialize(work_item(j)) for i = 1 to 2 initialize(work_item(i)) doSomething(work_item(i)) ...

JavaScript form input loop help

Hello, I have a form that currently only parses the first input variable in the POST. I have had to add multiple variables, so I would like the function to loop through and grab all the input parameters and add to the POST Here's the working code for grabbing the first name and value.... How can I get it to check the form and grab all ...

Avoiding a loop when entry i might take the value of entry i-1

I have vectors with mostly NA entries. I want to replace every NA with that vector's preceding non-NA entry. Specifically, the first entry will always be a 1, followed by a bunch of NAs, which I want to replace with 1. The ith entry could be another numeric, let's say 2, followed by more NAs that I want to replace with 2. And so on. The ...

search for value in mysql tables with less queries to the database?

Hi. I have a user with his unique username in a mysql table, but I have to test and do many queries to find it. I wonder if its a better way to avoid all does queries to the db. I have multiple rows in the table with columns like user1, user2, user3, user4 up to 30. for ($x=0; $x < 30; $x ++){ $user = "user"; $user .= $x; /...

how to calculate "consecutive mean" in R without using loop, or in a more efficient way?

I have a set a data that I need to calculate their "consecutive mean" (I dunno if it is the correct name, but I can't find anything better), here is an example: ID Var2 Var3 1 A 1 2 A 3 3 A 5 4 A 7 5 A 9 6 A 11 7 B 2 8 B 4 9 B 6 10 B 8 11 B 10 Here I need to calculat...

Create name of path files from list

I want to create path of files from list. pathList = [['~/workspace'], ['test'], ['*'], ['*A', '*2'], ['*Z?', '*1??'], ['*'], ['*'], ['*'], ['*.*']] and I want [['', '~/workspace', 'test', '*', '*A', '*Z?', '*', '*', '*', '*.*']] [['', '~/workspace', 'test', '*', '*A', '*1??', '*', '*', '*', '*.*']] [['', '~/workspace', 'test', '*'...

XSLT Filtering and indices on node set

Hi, I'm trying to retreive the previous node in a for-each using the preceding-sibling axis, a filter and an indexer to find it. The problem is, I only want the first item that matches the XPath in the selector however, I seem unable to apply both the filter and the indexer. The indexer seems to override the filter so I always get the ...

c# - How to produce string with 'and' in the correct place.

Here is the loop I have so far foreach (CheckBox chk in gpbSchedule.Controls.OfType<CheckBox>()) { if (chk.Checked) { //Code goes here } } The checkboxes all have text values of the days of the week. Monday, Tuesday ect....

C++: break the main loop

I am preparing some code: for(int a = 1; a <= 100; a++) //loop a (main loop) { for(int b = 1000; b <= 2000; b++) //loop b { if(b == 1555) break; } for(int c = 2001; c <= 3000; c++) //loop c { . . . } } I want to break the main loop (loop variable int a) by using a...