foreach

Objective-C Loop Through NSMutableArray?

Hello! Very simple question - how might I iterate through a NSMutableArray and do things for each item? Much like the for loop in other langs: foreach(array){ dosomething(); } Thanks! Christian Stewart ...

Is IEnumerable required to use a foreach loop?

I was wondering, when exactly can I use the foreach loop? Do I have to implement IEnumerable? ...

Alternative to IEnumerable<T>.Skip(1).Take(1).Single()

I am having a difficult time with a seemingly easy and embarrassing problem. All I want is the next element in an IEnumberable without using Skip(1).Take(1).Single(). This example illustrates the basic problem. private char _nextChar; private IEnumerable<char> getAlphabet() { yield return 'A'; yield return 'B'; yield retur...

ASP.NET Code Behind - DB data to HTML

Howdy! :D How are ya? I'm a PHP developer initiating my studies of ASP.NET, out of necessity, and I would like to know the easier way to retrieve some data from DB into an array and use this array to write some HTML. In PHP I'd pull the data, then use a foreach() loop to write, for example, rows of a table. But I don't have idea of how ...

Is there a way to test a variable for "isForEachable"

Using PHP, is there a function/method/way to check if a variable contains something that would be safe to put into a foreach construct? Something like //the simple case, would probably never use it this bluntly function foo($things) { if(isForEachable($things)) { foreach($things as $thing) { $thing->...

accessing value of next() and rewind() in a PHP iterator run in a foreach loop

Saw this in wikipedia, this is what happens when you traverse an iterator via a foreach loop: These methods are all being used in a complete foreach( $object as $key=>$value ) sequence. The methods are executed in the following order: rewind() while valid() { current() in $value key() in $key next() } End of L...

How to iterate over an array of stdObject elements in PHP?

This is the print_r() version of a data structure that I need to access via a foreach loop: stdClass Object ( [DetailedResponse] => Array ( [0] => stdClass Object ( ... ) [1] => stdClass Object ( ... Now, how do I iterate though these objects? I can...

Getting rid of nested foreach loops when using linq

I am always finding myself creating linq expressions that still use nested foreach loops heavily. Below is a simple example of what I'm talking about, and I'd really appreciate it if someone on here can show me how to condense this low-efficiency code into a single linq expression? The database context (db) has three tables: Blog, Tag, ...

Remove foreach - c# code-optimization

How to optimize this code? ParentDoglist, ChildDoglistis - Ilist. dogListBox - List Box foreach (Dog ParentDog in ParentDoglist) { foreach (Dog ChildDog in ChildDoglist) { if(ParentDog.StatusID==ChildDog.StatusID) dogListBox.Items.Add(new ListItem(ParentDog.Name, ParentDog.Key)); } } EDIT: ParentDogTypeList, DogTypeList were ...

why is a captured variable not holding a reference to the instance of an object

As the code shows below, I'm creating a thread in a foreach loop and running them at a later time, however when I run the thread I get the "object reference not set to an instance of an object" error. I suspect this is a closure problem, but it seems like i'm doing everything i should be to avoid that here by creating a local copy of th...

PHP Fatal error: Cannot break/continue

if (isset($errors)) { foreach ($errors as $error) { echo $error; } } else {break 2;} // some more code Outputs Fatal error: Cannot break/continue 2 levels I tried brake 1 not working either. ...

c# getting a list from a field out of a list

Hi, I'm sorry about the confusing title, but i didnt find a better way to explain my issue. I have a list of objects,myList, lets call them 'MyObject'. the objects look something like this: Class MyObject { int MYInt{get;set;} string MYString{get;set;} } List<MyObject> myList; ... I am looking for a nice/short/fancy way to ...

How to implode foreach

How to implode foreach() with comma? foreach($names as $name) { //do something echo '<a href="' . $url . '" title="' . $title . '">' . $name .'</a>'; } Want to add comma after each link, except the last one. ...

Parallel.ForEach Ordered Execution

I am trying to execute parallel fuctions on an list of objects using the new 4.0 Parallel.ForEach function. This is a very long maintenance process. I would like to make it execute in the order of the list so that I can stop and continue execution at the previous point. How do I do this? Here is an example. I have a list of object...

What is the purpose of the parentheses in Perl's `foreach` statement?

I always wonder why I must write foreach my $x (@arr) instead of foreach my $x @arr What is the purpose of the parentheses here? ...

PHP div for every 12 images

Hi again guys, i have this piece of code: <? include( "http://api.flickr.com/services/feeds/photos_public.gne?id=22352410@N07&amp;lang=en-us&amp;format=php" ); $i = 0; foreach($feed['items'] as $item) { preg_match("/<img src=\"([^\"]+)\" .*? \/>/", $item['description'], $matches); $img_html = $matches[0]; $img_src = $mat...

Linq Puzzle: How do I convert this foreach to linq syntax?

List<string> nameSpaceSuffixes = GetSuffixes(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach(var suffix in nameSpaceSuffixes) { if (assembly.GetName().Name.EndsWith(suffix)) Register(container, assembly, suffix); } } ...

Understanding Arrays as part of the foreach in php

Having: $a as $key => $value; is the same as having: $a=array(); ? Thanks in advance, MEM ...

php - printing keys with embedded function

I need help figuring out these php print (echo) statements and where to place them. I have an embedded function 'strotime' that is transforming time (column 'StartTime') to a format, but I cannot get it to print out correctly. No errors, just no changes or use of the function. Can someone help me figure out where to place this properly ...

LINQ or foreach - style/readability and speed

I have a piece of code for some validation logic, which in generalized for goes like this: private bool AllItemsAreSatisfactoryV1(IEnumerable<Source> collection) { foreach(var foo in collection) { Target target = SomeFancyLookup(foo); if (!target.Satisfactory) { return false; } } ...