nested-loops

knockout.js nested foreach access outer loop property

南楼画角 提交于 2019-12-03 04:39:39
I have a nested foreach loop in knockout.js and I want to access a property from the current object in the outer loop inside the inner loop. How would I do this? <!-- ko foreach: graduationDateRows --> <tr> <td class="center" data-bind="text: CalendarYear"></td> <!-- ko foreach: $root.graduationDatesHeaders --> <td class="center" data-bind="text: /* !here! */"></td> <td></td> <!-- /ko --> </tr> <!-- /ko --> You can use $parent to access one scope level up. So, from your inner loop you can use parent to access the current item being looped on in your graduationDateRows Stas Slabko You can even

How do exit two nested loops? [duplicate]

我们两清 提交于 2019-12-03 03:29:03
问题 This question already has answers here : How do I break out of nested loops in Java? (35 answers) Closed 3 years ago . I have been using Java for quite some time, yet my education in loops is somewhat lacking. I know how to create every loop that exists in java and break out of the loops as well. However, I've recently thought about this: Say I have two nested loops. Could I break out of both loops using just one break statement? Here is what I have so far. int points = 0; int goal = 100;

Why is there a significant difference in this C++ for loop's execution time? [duplicate]

不问归期 提交于 2019-12-03 02:32:53
问题 This question already has answers here : Why does the order of the loops affect performance when iterating over a 2D array? (7 answers) Closed 5 years ago . I was going through loops and found a significant difference in accessing loops. I can't understand what is the thing that causes such difference in both cases? First Example: Execution Time; 8 seconds for (int kk = 0; kk < 1000; kk++) { sum = 0; for (int i = 0; i < 1024; i++) for (int j = 0; j < 1024; j++) { sum += matrix[i][j]; } }

Looping through python regex matches

China☆狼群 提交于 2019-12-03 01:18:06
问题 This has to be easier than what I am running into. My problem is turning a string that looks like this: ABC12DEF3G56HIJ7 into 12 * ABC 3 * DEF 56 * G 7 * HIJ And I can't, for the life of me, design a correct set of loops using REGEX matching. The crux of the issue is that the code has to be completely general because I cannot assume how long the [A-Z] fragments will be, nor how long the [0-9] fragments will be. Thank you for any assistance! 回答1: Python's re.findall should work for you. Live

bash shell nested for loop

心已入冬 提交于 2019-12-02 18:06:25
I want to write a nested for loop that has to work in the bash shell prompt. nested for loop in Single line command. For example, for i in a b; do echo $i; done a b In the above example, for loop is executed in a single line command right. Like this I have tried the nested for loop in the shell prompt. Its not working. How to do this. Please update me on this. This is not a nested loop, just a single loop. And the nested version works, too: # for i in a b; do for j in a b; do echo $j; done; done a b a b One one line (semi-colons necessary): for i in 0 1 2 3 4 5 6 7 8 9; do for j in 0 1 2 3 4 5

How do exit two nested loops? [duplicate]

风格不统一 提交于 2019-12-02 17:00:45
This question already has an answer here: How do I break out of nested loops in Java? 35 answers I have been using Java for quite some time, yet my education in loops is somewhat lacking. I know how to create every loop that exists in java and break out of the loops as well. However, I've recently thought about this: Say I have two nested loops. Could I break out of both loops using just one break statement? Here is what I have so far. int points = 0; int goal = 100; while (goal <= 100) { for (int i = 0; i < goal; i++) { if (points > 50) { break; // For loop ends, but the while loop does not }

AlertController is being popped every time in nested conditions swift ios

╄→гoц情女王★ 提交于 2019-12-02 16:40:03
问题 I have defined an alertcontroller when username or password is not correct the alert should pop, and it is working fine. but when the username & password is matched despite matching it pops up everytime when log in. I think I have not defined nested condition in a right way? help me to sort the multiple nested condition. Code for Login import UIKit import CoreData import Foundation class ViewController: UIViewController { var usernameGlobal : String = "" @IBOutlet weak var emailText:

Why is there a significant difference in this C++ for loop's execution time? [duplicate]

こ雲淡風輕ζ 提交于 2019-12-02 16:05:13
This question already has an answer here: Why does the order of the loops affect performance when iterating over a 2D array? 7 answers I was going through loops and found a significant difference in accessing loops. I can't understand what is the thing that causes such difference in both cases? First Example: Execution Time; 8 seconds for (int kk = 0; kk < 1000; kk++) { sum = 0; for (int i = 0; i < 1024; i++) for (int j = 0; j < 1024; j++) { sum += matrix[i][j]; } } Second Example: Execution Time: 23 seconds for (int kk = 0; kk < 1000; kk++) { sum = 0; for (int i = 0; i < 1024; i++) for (int j

Looping through python regex matches

情到浓时终转凉″ 提交于 2019-12-02 15:03:50
This has to be easier than what I am running into. My problem is turning a string that looks like this: ABC12DEF3G56HIJ7 into 12 * ABC 3 * DEF 56 * G 7 * HIJ And I can't, for the life of me, design a correct set of loops using REGEX matching. The crux of the issue is that the code has to be completely general because I cannot assume how long the [A-Z] fragments will be, nor how long the [0-9] fragments will be. Thank you for any assistance! Ray Toal Python's re.findall should work for you. Live demo import re s = "ABC12DEF3G56HIJ7" pattern = re.compile(r'([A-Z]+)([0-9]+)') for (letters,

JavaScript get value from nested object [duplicate]

廉价感情. 提交于 2019-12-02 10:08:47
This question already has an answer here: JavaScript - retrieve value from nested object, using array of keys 1 answer If this is my object: var obj = { bakery1: { small: { name: "Small cookie", price: 0.75; } large: { name: "Large cookie", price: 3.00; } } bakery2: { small: { name: "Small cookie", price: 1.00; } large: { name: "Large cookie", price: 4.00; } } }; How would I go about making a loop that prints every price to the console? And when this value is printed, is there a way to trace the name? For example if the output is 3.00 how would I make a function that gives me the name that