for-loop

Break for loop in an if statement

吃可爱长大的小学妹 提交于 2019-12-28 20:48:32
问题 Currently having trouble with breaking this for loop. I want to break it if the variable is not found in this list so it can move two another for loop. It expects an indented block for the top of the for loop, but if I change the position of the break or of the start of the for loop, it doesn't work. Help! while cyclenumb <= 10000: for x in userpassword[k]: for z in lowercaselist: if x in z: newpasswordlist.append(z) k +=1 break else: for x in userpassword[k]: for z in uppercaselist: if x in

for of loop querySelectorAll

↘锁芯ラ 提交于 2019-12-28 20:41:41
问题 Mozilla states that "for of loops will loop over NodeList objects correctly". (source: https://developer.mozilla.org/en-US/docs/Web/API/NodeList) However, this doesn't work in Chrome 43. Is this incorrect documentation or a browser bug? The copied example code used on a page with checkboxes: var list = document.querySelectorAll( 'input[type=checkbox]' ); for (var item of list) { item.checked = true; } 回答1: Edit: This is shipping in Chrome 51. Jake Archibald posted a simple fix: NodeList

How to speed up or vectorize a for loop?

吃可爱长大的小学妹 提交于 2019-12-28 16:02:29
问题 I would like to increase the speed of my for loop via vectorization or using Data.table or something else. I have to run the code on 1,000,000 rows and my code is really slow. The code is fairly self-explanatory. I have included an explanation below just in case. I have included the input and the output of the function. Hopefully you will help me make the function faster. My goal is to bin the vector "Volume", where each bin is equal to 100 shares. The vector "Volume" contains the number of

Python `for` syntax: block code vs single line generator expressions

前提是你 提交于 2019-12-28 09:06:49
问题 I'm familiar with the for loop in a block-code context. eg: for c in "word": print c I just came across some examples that use for differently. Rather than beginning with the for statement, they tag it at the end of an expression (and don't involve an indented code-block). eg: sum(x*x for x in range(10)) Can anyone point me to some documentation that outlines this use of for ? I've been able to find examples, but not explanations. All the for documentation I've been able to find describes the

Permutation of Array PHP

北慕城南 提交于 2019-12-28 07:05:20
问题 I have the following problem: $multidmimensional = array( [0] => array( [0] => 1, [1] => 2, [2] => 3 ); [1] => array( [0] => 5, [1] => 6, [2] => 7 ); ... [2] => array( [0] =>,4 [1] => 5, ); ); I can have one or more (nested) arrays, and lets take as an example the first two of the above arrays: I should permutate them in the following way: 15 16 17 25 26 27 36 37 38 If I had for example those three arrays, I should get a result like this: 154 164 174 155 165 175 254 264 274 255 265 275 364

Permutation of Array PHP

旧城冷巷雨未停 提交于 2019-12-28 07:04:26
问题 I have the following problem: $multidmimensional = array( [0] => array( [0] => 1, [1] => 2, [2] => 3 ); [1] => array( [0] => 5, [1] => 6, [2] => 7 ); ... [2] => array( [0] =>,4 [1] => 5, ); ); I can have one or more (nested) arrays, and lets take as an example the first two of the above arrays: I should permutate them in the following way: 15 16 17 25 26 27 36 37 38 If I had for example those three arrays, I should get a result like this: 154 164 174 155 165 175 254 264 274 255 265 275 364

jQuery Looping and Attaching Click Events

蹲街弑〆低调 提交于 2019-12-28 07:01:28
问题 Okay I've tried multiple things and looked for answers to this and I can't seem to get it to work. What I'm trying to do is there are some dynamically generated images, so I don't know how many images there will be at any time. Each image has some associated information that I store in a seperate div. What I want to do is attach a click event to each image that will unhide the div that has the associated content in it. I've tried looping with both a for loop and a while loop, to no avail.

Java for-loop optimization

北战南征 提交于 2019-12-28 06:49:29
问题 I made some runtime tests with java for loops and recognized a strange behaviour. For my code I need wrapper objects for primitive types like int, double and so on, to simulate io and output parameters, but thats not the point. Just watch my code. How can objects with field access be faster then primitive types? for loop with prtimitive type: public static void main(String[] args) { double max = 1000; for (int j = 1; j < 8; j++) { double i; max = max * 10; long start = System.nanoTime(); for

javascript: Using the current for-loop counter-value inside a function() { }?

笑着哭i 提交于 2019-12-28 06:36:10
问题 on a website i want to do this: (simplified) myHandlers = new Array(); for(var i = 0; i < 7; i++) { myHandlers.push(new Handler({ handlerName: 'myHandler'+i, // works, e.g. ->myHandler1, 2, 3 etc. handlerFunc: function(bla) { /*...*/ alert(i); } // doesn't work,all return 7 } } I could set the counter as another attribute of my Handler (which would copy the current value) and use it inside my function, but I guess, there is also a way to actually copy this value, no? 回答1: When handlerFunc is

how to skip elements in foreach loop

独自空忆成欢 提交于 2019-12-28 05:49:27
问题 I want to skip some records in a foreach loop. For example, there are 68 records in the loop. How can I skip 20 records and start from record #21? 回答1: Five solutions come to mind: Double addressing via array_keys The problem with for loops is that the keys may be strings or not continues numbers therefore you must use "double addressing" (or "table lookup", call it whatever you want) and access the array via an array of it's keys. // Initialize 25 items $array = range( 1, 25, 1); // You need