Все вопросы: [foreach]

204 вопросов

12
голосов
5ответов
14637 просмотров

Why is foreach iterating with a const reference?

I try to do the following: QList<QString> a; foreach(QString& s, a) { s += "s"; } Which looks like it should be legitimate but I end up with an error complaining that it cannot convert from 'const QString' to 'QString &'. Why is the Qt foreach iterating with a const reference?

5
голосов
5ответов
1865 просмотров

Question about foreach and delegates

Suppose the following code: foreach(Item i on ItemCollection) { Something s = new Something(); s.EventX += delegate { ProcessItem(i); }; SomethingCollection.Add(s); } Of course, this is wrong because all the delegates points to the same Item. The alternative is: foreach(Item i on Ite...

0
голосов
1ответов
4158 просмотров

Changing the BackColor of my custom UserControl - help!

(lol) I have a panel on Form1. I'm going to add several instances of my custom usercontrol MovieItem to that panel. To do this I'm going: panel1.Controls.Add(objMovieItem); Now, within the MovieItem.cs code I'm adding the .Click events of everything inside the UserControl so that whenever a ...

9
голосов
7ответов
6912 просмотров

Challenge: C# Foreach - Before, After, Even, Odd, Last, First

Since C# doesn't have a before,after,last,first etc. as part of its foreach. The challenge is to mimic this behavior as elegantly as possible with the following criteria: Must allow: before, first, even, odd, last, after events Give an option execute/not execute the primary function (function e...

2
голосов
4ответов
4551 просмотров

looping through a object which contains an object php

I have a PHP Object which contains other objects i.e $obj->sec_obj->some_var; I want to use a foreach loop to loop through the object and all objects objects. I think the max level is 3, so $obj->sec_obj->third_obj->fourth_obj Any ideas?

0
голосов
6ответов
1186 просмотров

help with php FOREACH loop

can some please tell me what's wrong with the bellow foreach php loop. foreach ($_POST[sortlist] as $key => $value) { $sql = "UPDATE sortable SET color_order = " . mysql_real_escape_string($key) . " WHERE id = " . mysql_real_escape_string($value); $result =...

2
голосов
5ответов
11581 просмотров

php function to return sql results that contain arrays, as an array

So im having a problem (obviously). I have the following MySQL table data 7 USER1 1,1,1,10,1 The Guys Team 8,7,13,14,16 8 USER1 1,1,1,10,1 The Girls Team 7,12,15 10 USER1 1,1,1,10,1 Dog Team 8,7,14,15 I wrote a function to retrieve the data, and return it. ...

0
голосов
1ответов
818 просмотров

Php foreach loop, with looping error messages

I have a foreach loop that is suppose to check to see if a checkbox is checked by an item. If the checkbox is checked I need to see if the file upload part of the script has a value and if so then proceed to check the file type and size of the file the user is trying to upload. Currently if the...

9
голосов
13ответов
65024 просмотров

How can I know a row index while iterating with foreach?

in the next example how can I know the current row index? foreach (DataRow temprow in temptable.Rows) { //this.text = temprow.INDEX???? }

4
голосов
8ответов
8356 просмотров

Reference to the iteration number in Java's foreach

How can you refer to the index of an array in the foreach? My code String[] name = { "hello", "world" }; for ( int k : name[k] ) { --- cut --- } I expecting that the foreach -loop will 1. set k = 0 in first iteration so that name[0] works correctly 2. set k = 1 in the next iteration... ...

68
голосов
10ответов
47196 просмотров

Does foreach() iterate by reference?

Consider this: List<MyClass> obj_list = get_the_list(); foreach( MyClass obj in obj_list ) { obj.property = 42; } Is obj a reference to the corresponding object within the list so that when I change the property the change will persist in the object instance once constructed somewhere?

23
голосов
3ответов
11970 просмотров

Removing XElements in a foreach loop

So, I have a bug to remove foreach (XElement x in items.Elements("x")) { XElement result = webservice.method(x); if (/*condition based on values in result*/) { x.Remove(); } } The problem is that calling x.Remove() alters the foreach such that if there are two Elemen...

88
голосов
5ответов
162348 просмотров

How to loop through a collection that supports IEnumerable?

How to loop through a collection that supports IEnumerable?

0
голосов
2ответов
417 просмотров

XSLT : how to know I went inside any of several for-each?

I have several <xsl:for-each/> which run the one after the other. I would like, at the end, to do something if I did not pass in any of them. For only one for-each, I can manage to make a <xsl:choose/> with an appropriate test based on the selector in the for-each, but for a lot of th...

1
голосов
3ответов
930 просмотров

c# How to add an eventhandler to many menus in a foreach loop?

I'm working with the compact framework and i'm making an app for a windows mobile standard. I have an array which contain phonenumbers, and i want to add a submenu foreach number i find in that array. These submenus must be clickable, but i can't figure out how to do it. This is my code: ...

0
голосов
2ответов
298 просмотров

Unexpected behaviour with PHP array references

I'm using references to alter an array: foreach($uNewAppointments as &$newAppointment) { foreach($appointments as &$appointment) { if($appointment == $newAppointment){ $appointment['index'] = $counter; } } $newAppointment['index'] = $counter; ...

0
голосов
5ответов
2106 просмотров

PHP - Foreach (Array of an Array)

Here is an example: for($i=1; $i < 10; $i++){ $marray[] = array($name, $email, $password); // Lets just say for now, there is real // data for each online being input } foreach ($marray as $e){ echo "Name: ". $e[0]; echo "Email: ". $e[1]...

194
голосов
6ответов
395527 просмотров

Linq style "For Each"

Is there any Linq style syntax for "For each" operations? For instance, add values based on one collection to another, already existing one: IEnumerable<int> someValues = new List<int>() { 1, 2, 3 }; IList<int> list = new List<int>(); someValues.ForEach(x => list.Ad...

2
голосов
4ответов
1443 просмотров

Whats the replacement of For-Each loop for filtering?

Though for-each loop has many advantages but the problem is ,it doesn't work when you want to Filter(Filtering means removing element from List) a List,Can you please any replacement as even traversing through Index is not a good option..

1
голосов
4ответов
6518 просмотров

Check Upload file type from an array in PHP.

How can I check if a file extension and mime type are in an array this is the code I currently have. $upload_project_thum = $_FILES['upload_project_thum']['name']; $upload_project_thum_ext = substr($upload_project_thum, strrpos($upload_project_thum, '.') + 1); $upload_permitted_types= arra...

1
голосов
4ответов
2851 просмотров

C# Not Disposing controls like I told it to

I have a Panel control. And inside the panel users can add combobox's, textbox's labels etc and drag them around and stuff, and there's a Delete button on my form where if they click it, it will delete all controls inside that panel. BUT this code: foreach( Control control in panel.Controls ) { ...

2
голосов
4ответов
1031 просмотров

edit list inside foreach loop

I have an object with the following structure: (pseudocode) class Client { - int ID - int? ParentID - string Name - datetime CreateDate - int ACClientID - List <Client> Clients } I want to loop through the whole nested structure using a recursive foreach, to set the ACClientID of ALL to ...

4
голосов
3ответов
2331 просмотров

Is there a way to modify foreach loop variable?

The following code gives an error message: #!/usr/bin/perl -w foreach my $var (0, 1, 2){ $var += 2; print "$var\n"; } Modification of a read-only value attempted at test.pl line 4. Is there any way to modify $var? (I'm just asking out of curiosity; I was actually quite surprised to s...

1
голосов
10ответов
256 просмотров

In C# 3.0 is there any syntax for a block of code that will run only if a foreach doesn't have any iterations?

meaning something like... foreach(blah b in blahblahs) { writeOnMoon(b.name); } default { writeOnMoon("No Blahs!"); } default or, otherwise, or something like that, if this does not exist... do you think it should?

3
голосов
4ответов
4015 просмотров

foreach loop does not loop through all item in list - C#

I have a basic foreach loop that calls a static method which makes a connection to a database and inserts some data. For some reason it will only iterate through the first item in the collection when I run the application without debugging. If I debug the application and set a break point on th...

0
голосов
3ответов
825 просмотров

jquery fading sequence

I am attempting to fade in a set of divs, one after another. I thought I could use the simple For Each function that jquery offers. My code is as follows: $('#menu_activate').click(function(){ $('div.section').each(function(i){ $(this).fadeToggle(); }); }); The good thing about th...

0
голосов
3ответов
112 просмотров

Array, how to display the "changing values" only

Let's say I have an array with dates and seasons, there is one entry for each day. I would like to print the array row only when the season value is changing. the array look like that: 2009-10-28 00:00:00 (good season) 2009-10-29 00:00:00 (good season) 2009-10-30 00:00:00 (good season) 2...

0
голосов
1ответов
191 просмотров

mysql_list_tables into foreach array?

Is it possible to list my tables into a foreach array? current code. $browsers = array ("site1", "site2", "site3"); foreach($browsers as $browser) { $domain = $browser; include ('code.php'); }

37
голосов
10ответов
126001 просмотров

How can I get the current array index in a foreach loop?

How do I get the current index in a foreach loop? foreach ($arr as $key => $val) { // How do I get the index? // How do I get the first element in an associative array? }

3
голосов
1ответов
490 просмотров

Creating a foreach keyword with yacc or Bison and Flex

I have developed a interpreted programming language. It is strongly based on C. The problem is, I want to add a foreach directive and have no clue how to. I am using Bison and Flex as the parser and lexer generator.