foreach

'for' loop vs Qt's 'foreach' in C++

只愿长相守 提交于 2020-01-09 15:03:10
问题 Which is better (or faster), a C++ for loop or the foreach operator provided by Qt? For example, the following condition QList<QString> listofstrings; Which is better? foreach(QString str, listofstrings) { //code } or int count = listofstrings.count(); QString str = QString(); for(int i=0;i<count;i++) { str = listofstrings.at(i); //Code } 回答1: It really doesn't matter in most cases. The large number of questions on StackOverflow regarding whether this method or that method is faster, belie

Array shows 0 as length when it has elements in it

橙三吉。 提交于 2020-01-09 10:54:13
问题 So I have an object like so: this.$ - this holds indexes that hold arrays. For instance, it has two different indexes: one called slide and one called thumb . Those indexes hold arrays. I'm developing in vue and got those to show up with the v-ref attribute. However, whenever I do this: console.log(this.$.slide.length) It comes back as 0. I'm trying to loop through it using forEach() but can't since it shows 0 even though there are clearly 4 VueComponent objects inside that array. I'm not

How to use promise in forEach loop of array to populate an object

有些话、适合烂在心里 提交于 2020-01-09 06:23:25
问题 I am running a forEach loop on an array and making two calls which return promises, and I want to populate an object say this.options , and then do other stuff with it. Right now I am running into the async issue if i use the following code sample and i get into the then function first. $.when.apply($, someArray.map(function(item) { return $.ajax({...}).then(function(data){...}); })).then(function() { // all ajax calls done now }); This is working code below, but it only works for the first

How is an array in a PHP foreach loop read?

情到浓时终转凉″ 提交于 2020-01-09 03:22:11
问题 We have all heard of how in a for loop, we should do this: for ($i = 0, $count = count($array); $i < $c; ++$i) { // Do stuff while traversing array } instead of this: for ($i = 0; $i < count($array); ++$i) { // Do stuff while traversing array } for performance reasons (i.e. initializing $count would've called count() only once, instead of calling count() with every conditional check). Does it then also make a difference if, in a foreach loop, I do this: $array = do_something_that_returns_an

An example for supporting foreach without implementing IEnumerable

℡╲_俬逩灬. 提交于 2020-01-08 04:00:15
问题 I am looking at this blog which explains that foreach can be supported without implementing IEnumerable . But does not go into the details of the implementation. I am looking for an example of how to support foreach without implementing IEnumerable . Edit: Thanks to @Sam I am 's comment, I got what I was looking for. (see my answer below) 回答1: Here is a class that doesn't implement IEnumerable , or any interfaces at all: public class Foo { public IEnumerator<int> GetEnumerator() { yield

An example for supporting foreach without implementing IEnumerable

半世苍凉 提交于 2020-01-08 03:59:53
问题 I am looking at this blog which explains that foreach can be supported without implementing IEnumerable . But does not go into the details of the implementation. I am looking for an example of how to support foreach without implementing IEnumerable . Edit: Thanks to @Sam I am 's comment, I got what I was looking for. (see my answer below) 回答1: Here is a class that doesn't implement IEnumerable , or any interfaces at all: public class Foo { public IEnumerator<int> GetEnumerator() { yield

Rename uploaded files

南笙酒味 提交于 2020-01-07 07:07:11
问题 I am uploading files via php. The amount of files can be uploaded is determined by a value which is stored in database. So let's say, this value is 3, than my code show three html file input. This is working. I could also rename one file too. working extension filter, and size restrictions.. But when I tried to do this with more than one, I stacked... The new name should be the 'number of list element'-'base filename'. Example: 1-thisisanimage.jpg 2-anotherimage.jpg 3-andthisalso.jpg I tried

SSIS ForEach Loop behaviour

做~自己de王妃 提交于 2020-01-07 06:55:49
问题 This is typical ForEach container behaviour: However, if I do whats shown in the image below, the Execute SQL task never executes, how can i do this behaviour? I do not have to use ForEach container if some other type of container will allow me to do this. The for each loop essentially loops through files in multiple subdirectories in a folder. Based on which folder the loop is in, it populates a variable. this variable is used in the connectors from "some script" task to "task a" and "task b

PHP, stdClass, select elements contains specifed element

妖精的绣舞 提交于 2020-01-07 06:50:14
问题 I have an stClass object like this: object(stdClass)#2 (6) { [0]=> object(stdClass)#44 (2) { ["uid"]=> int(3232) ["type"]=> string(7) "sibling" } [1]=> object(stdClass)#43 (2) { ["uid"]=> int(32323) ["type"]=> string(7) "sibling" } [2]=> object(stdClass)#42 (2) { ["uid"]=> int(3213) ["type"]=> string(10) "grandchild" } [3]=> object(stdClass)#41 (3) { ["uid"]=> int(-680411188) ["type"]=> string(6) "parent" } [4]=> object(stdClass)#40 (3) { ["uid"]=> int(-580189276) ["type"]=> string(6) "parent

List number in array php

回眸只為那壹抹淺笑 提交于 2020-01-07 05:22:06
问题 for my work, i must to send multiples sms with an api and i want to put numbers in array from mysql like this : (the numbers are in my database) I want like this : $list_num = array( '0601020301','0601020302','0601020303','0601020304','0601020305','0601020306','0601020307','0601020308','0601020309','0601020310', '0601020311','0601020312','0601020313','0601020314','0601020315','0601020316','0601020317','0601020318','0601020319','0601020320', '0601020321','0601020322','0601020323','0601020324',