foreach

for vs foreach vs while which is faster for iterating through arrays in php

which one is the fastest for iterating through arrays in php? or does another exist which is also faster for iterating through arrays? ...

How to Checkpoint while using For Each Loop container in SSIS

How can I use Checkpoints while I am using For Each Loop containers in an SSIS package? Whenever I try and rerun the package it starts from the beginning of the foreach loop container instead of from where it failed. The checkpoint seems to have trouble with for each loop containers. I created a table insert to help me identify where ...

Display custom text if asp.net mvc for each loop is empty

Still learning asp.net and mvc, please be gentle :) Currently setting up an MVC view to consume and display an RSS feed, using this method described on CodeProject. What I want to do is when no items are returned for the RSS feed, display a custom piece of text, eg something like the following piece of psuedocode. If ViewData.Model.It...

foreach through a session variable

I would like iterate on each Object in my session variable. 'items' is of type item which is a class I've created to store book information. I have done a count($_SESSION['items']) which returns a 1 so i thought it should iterate at least once. But no luck. Thanks foreach ($_SESSION['items'] as $item) { echo TEST; $sql = 'SEL...

Performance and foreach loop in .NET

I have the following click event. protected void btnUpdate_Click(object sender, EventArgs e) { foreach (GridViewRow gvr in gvEditBulletins.Rows) { RadEditor re = (RadEditor)gvr.FindControl("reBulletin"); DropDownList ddl = (DropDownList)gvr.FindControl("ddlPosition"); // Business logic ...

Is there a Ruby version of for-loop similar to the one on Java/C++ ?

Is there a Ruby version of for-loop similar to the one in Java/C(++)? In Java: for (int i=0; i<1000; i++) { // do stuff } The reason is because I need to do different operations based on the index of the iteration. Looks like Ruby only has a for-each loop? Am I correct? ...

Is it possible to iterate over arguments in variadic macros ?

Hi, I was wondering if it is possible to iterate over arguments passed to a variadic macro in C99 or using any GCC extensions ? For e.g. is it possible to write a generic macro that takes a structure and its fields passed as arguments and prints offset of each field within the structure ? Something like this: struct a { int a; ...

Declaring a variable inside or outside an foreach loop: which is faster/better?

Which one of these is the faster/better one? This one: List<User> list = new List<User>(); User u; foreach (string s in l) { u = new User(); u.Name = s; list.Add(u); } Or this one: List<User> list = new List<User>(); foreach (string s in l) { User u = new User(); u.Name = s; list.Add(u); } My newbie-devel...

fetching values from map in jstl

Hi, I have the following code on my jsp page: <c:out value="${items}" /><br /> <c:forEach items="${items}" var="item"> 1. <c:out value="${item.key}" /><br /> 2. <c:out value="${item.key eq 70}" /><br /> 3. <c:out value="${items[70]}" /><br /> 4. <c:out value="${items[item.key]}" /><br /> </c:forEach> And it produc...

for each ... break

I feel dirty every time I "break" out of a for-each construct (PHP/Javascript) So something like this: // Javascript example for (object in objectList) { if (object.test == true) { //do some process on object break; } } For large objectLists I would go through the hassle building a more elegant solution. But ...

C# *Strange* problem with StopWatch and a foreach loop

I have the this code: var options = GetOptions(From, Value, SelectedValue); var stopWatch = System.Diagnostics.Stopwatch.StartNew(); foreach (Option option in options) { stringBuilder.Append("<option"); stringBuilder.Append(" value=\""); stringBuilder.Append(option.Value); stringBuilder.Append("\""); if (opti...

PHP - foreach how to store the array to mysql

I want to store array into mysql db something like this item_row = nike,adidas,puma qty_row = 1,3,2 total_row = 100,200,150 foreach foreach ($_SESSION['order'] as $values) { $item_name = $values['item-name']; $item_qty = $values['item-qty']; $item_price = $values['item-price']; } Let me know how to do that?...

C#: Any benefit of List<T>.ForEach(...) over plain foreach loop ?

I'm wondering why List<T>.ForEach(Action<T>) exists. Is there any benefit/difference in doing : elements.ForEach(delegate(Element element){ element.DoSomething(); }); over foreach(Element element in elements) { element.DoSomething();} ? ...

looping through a set of radio buttons and find if its empty in PHP

my question is that i have a group of radio buttons and all are grouped into one 'x0'.Now how do i iterate through this radiobutton group using foreach ,and find if its empty/or not and do further operations based on the value? <tr> <td><input type="radio" name="x0" value="0" <?=$x0?>> 0. </td> </tr> <tr> <td><input type="r...

Separate calls to Db data in one foreach loop

OK I hope this isn't too specific. I have a database driven CMS that a coworker uses with many categories in it. Here's how it echoes some products we have now: $offers = get_offers('category1','none','compare'); foreach ($offers as $row) { $offername = $row['name']; $offerlogo = $row['logo']; $offera=$row['detailA']; ...

PHP - foreach affects session value

How can foreach loop affect session variable? session_start(); $_SESSION[test] = "Session content"; echo $_SESSION[test].'<br />'; $test_array = array("test", "array", "something", "array end"); foreach($test_array as $test){ echo $test.'<br />'; } echo '<br />Session content after foreach: '.$_SESSION[test].'<br />'; When I ru...

Memory Usage in Foreach Function

I was wondering if there is any way to get the foreach package in R to use a pre-allocated structure to put results. basically it involves lots of small linalg operations on very big data sets. My non-foreach original code is something like results <- rep(NA,m*l*[big.number]) dim(results) <- c(m,l,[big.number]) for (i in 1:m){ for ...

When the property is getted in a ForEach loop?

Hello, I have a property getter with a lock like this one: Public ReadOnly Property ActiveClientList() as List(Of TcpClient) Get SyncLock(m_activeClientListLock) Return m_activeClientList End SyncLock End Get End Property When I do a ForEach loop when is the property getted? I mean, in this loop wh...

Auto incrementing number in PHP foreach loop

This is the beginning of a php for loop. I would like to edit it so that 'INSERT NUMBER HERE' gets replaced with an incrementing number. Ie. first loop it would be 1, then 2, then 3 etc. <?php foreach ($_productCollection as $_product): ?> <div style="float: left; font-size: 120px;height:50px;padding-top:50px; color:#ccc">INSERT N...

limiting number of times a loop runs in php

I have a foreach loop that i need to limit to the first 10 items then break out of it. How would i do that here? foreach ($butters->users->user as $user) { $id = $user->id; $name = $user->screen_name; $profimg = $user->profile_image_url; echo "things"; } Would appreciate a detailed explanation as well. ...