foreach

Modifying each item of a List in java

筅森魡賤 提交于 2020-05-09 20:45:10
问题 I'm just starting to work with lists in java. I'm wondering what the recommended method to modify each element of a list would be? I've been able to get it done with both the following methods, but they both seem fairly unelegant. Is there any better way to get this done in java? And is any of the below methods recommended over the other, or are both on the same level? //Modifying with foreach for (String each : list) { list.set(list.indexOf(each), each+ " blah"); } //Modifying with for for

MVC Razor, add if statement to foreach loop

…衆ロ難τιáo~ 提交于 2020-05-07 18:25:12
问题 I'm trying to add data from my model to a table with razor. My problem is that i want an if statement to decide what class the tagg should be and i can't get this to work. When i add the if i get the following error when i run the code The foreach block is missing a closing "}" character How should i add the if statement? This is my current code @{ var counter = 0; } @foreach (var item in Model) { if(item.status == "Active") { <tr> } else { <tr class="danger"> } <td>@counter</td> <td>@item

MVC Razor, add if statement to foreach loop

99封情书 提交于 2020-05-07 18:25:04
问题 I'm trying to add data from my model to a table with razor. My problem is that i want an if statement to decide what class the tagg should be and i can't get this to work. When i add the if i get the following error when i run the code The foreach block is missing a closing "}" character How should i add the if statement? This is my current code @{ var counter = 0; } @foreach (var item in Model) { if(item.status == "Active") { <tr> } else { <tr class="danger"> } <td>@counter</td> <td>@item

SwiftUI app crashes every time when trying to add item to grouped items

天大地大妈咪最大 提交于 2020-04-18 03:46:32
问题 My app crashes and I am getting a following error when I try to sort items by date in a ForEach loop: 2020-03-24 16:55:13.830146+0700 list-dates[60035:2135088] *** Assertion failure in -[_UITableViewUpdateSupport _setupAnimationsForNewlyInsertedCells], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3901.4.2/UITableViewSupport.m:1311 (lldb) on line: class AppDelegate: UIResponder, UIApplicationDelegate { of AppDelegate.swift At first my app loads in simulator, but after I

Remove an item in a list while it's in a foreach loop c# [duplicate]

半世苍凉 提交于 2020-04-13 06:10:49
问题 This question already has answers here : Intelligent way of removing items from a List<T> while enumerating in C# (9 answers) How to remove elements from a generic list while iterating over it? (26 answers) Closed 4 years ago . If I use an item in a foreach loop and I can't use the item it has to delete the item that is currently in the foreach loop. This is the code that I have right now: foreach (Line line in linelijst) { try { if (line.ActorIndex() == 0) { line.setStartPoint(actorenlijst[0

List.forEach unable to modify element?

浪尽此生 提交于 2020-04-13 05:54:33
问题 I'm attempting to create a list of lists to imitate the functionality of a 2D array in Dart, and I was having trouble for a while figuring out how to make it work. I originally used List.forEach in order to create the lists and fill them, but after each loop, it's as if I never created the lists. Here's what that code looked like: currentMap = new List<List<int>>(height); currentMap.forEach((e) { e = new List<int>(width); e.forEach((f) { f = 1; }); }); Printing currentMap resulted in a list

How to get WooCommerce product variation values

爷,独闯天下 提交于 2020-04-10 06:28:48
问题 I want to be able to list the the variation option values. For example I have a lantern that comes in 12in, 14in and 16in. I want to be able to get these values. I have been trying to use the foreach loop to get these values but I need a little help. here's my code; function test_func(){ global $woocommerce, $product, $post; // test if product is variable if( $product->is_type( 'variable' ) ){ $available_variations = $product->get_available_variations(); // var_dump($available_variations);

How to get WooCommerce product variation values

橙三吉。 提交于 2020-04-10 06:27:39
问题 I want to be able to list the the variation option values. For example I have a lantern that comes in 12in, 14in and 16in. I want to be able to get these values. I have been trying to use the foreach loop to get these values but I need a little help. here's my code; function test_func(){ global $woocommerce, $product, $post; // test if product is variable if( $product->is_type( 'variable' ) ){ $available_variations = $product->get_available_variations(); // var_dump($available_variations);

how to group array of objects by value in reactjs / javascript

社会主义新天地 提交于 2020-04-10 05:27:13
问题 I have an array of object that have different values like items=[{id:1,category:"cat_1" , title:"My title 1"},{id:2,category:"cat_2" , title:"My title 2"},{id:6,category:"cat_1" , title:"Another title 1"},{id:1,category:"cat_3" , title:"My title 3"},{id:8,category:"cat_1" , title:"Third Title"},{id:2,category:"cat_2" , title:"Another title 2 "}] I use array map to list the object and display them as { items.map((item) => ( <h1>{item.category}</h1> <p>{item.title}</p> ))} My question is how do

Process optimisation of code within dopar

江枫思渺然 提交于 2020-03-26 04:03:54
问题 I am trying to optimize my code to run glms multiple times, and I would like to leverage parallelization, either with foreach or some other more efficient way. As you can see; the for loop takes about 800 secs to run 270000 glms; while foreach with dopar unintuitively takes for ever (It either crashes or I force it to stop after a couple of hours). Thanks for your help. Jinesh library(data.table) library(parallel) library(doParallel) library(foreach) scen_bin <- expand.grid(n = c(10, 20, 30),