Questions tagged as 'foreach'

3
answers

foreach is a loop or iterator? Or could it be both?

In a video tutorial the instructor said not to fall into foolish to think that the foreach loop is one, and was vehement that he was an iterator. There are cases where we can scroll through the items in an array using foreach as a "compact fo...
asked by 05.03.2017 / 23:34
2
answers

Optimize foreach

I need to check if listaContrato items exist in listaPendencia , if there is no enable to false to be disabled on the screen. What can I do to improve the performance of foreach below? Both lists are List<>...
asked by 10.11.2016 / 15:18
3
answers

Why do I need to declare a type within Foreach?

Why in%% we need to always declare a variable. Example: for(Pessoa pessoa : pessoas) { //qualquer coisa } In other words, I want to know why you can not do this: Pessoa pessoa; for(pessoa : pessoas) { //qualquer co...
asked by 02.02.2016 / 01:18
2
answers

How to check if a value is iterable by foreach in PHP?

In PHP, not only arrays are iterable, but also some specific objects. For example, objects that implement the interface Iterator or even IteratorAggregate . Another example is stdClass and ArrayObject , which ite...
asked by 11.01.2017 / 12:42
2
answers

Foreach C # vs ForEach () EF6

Follow the code below: % of EF6%: var result = ctx.Table.Where(x => x.User == "João").ToList(); result.ForEach(x => x.Read = true); ctx.SaveChanges(); ForEach() of C #: var result = ctx.Table.Where(x => x.User == "João...
asked by 07.06.2017 / 20:45
2
answers

Which one performs better? For or Foreach + Range?

In the two ways below, which one performs better? For : for( $x=1; $x < 31; $x++ ) echo $x . PHP_EOL; Foreach + range : foreach( range(1,30) as $x ) echo $x . PHP_EOL; I know the difference will proba...
asked by 08.05.2015 / 21:03
2
answers

Variable of foreach loop

When we use a foreach loop, does the local variable we create to receive the content of the list in question pass by value or reference? Ex: foreach (var item in listItems) { //TODO } Does item receive content by value o...
asked by 24.08.2017 / 16:31
2
answers

Which loop is faster for or foreach in C #?

I've read articles from some programming languages that the for loop is faster than the foreach , and was wondering if C # has performance differences? >     
asked by 12.10.2016 / 23:21
2
answers

Exit two Foreachs PHP

I need to iterate several collections and if I find a condition I have to exit more than one iteration loop. Ex: foreach ($order->getItemCollection() as $item) { foreach ($order->getFreight()->getPackageCollection() as...
asked by 06.10.2014 / 20:47
2
answers

Why can this happen in a foreach?

I built two simple classes: import java.util.ArrayList; import java.util.List; public class Aluna { String nome; String idade; String cpf; List<Aluna> listar(){ ArrayList<Aluna> aluns = new ArrayList<>(); Aluna...
asked by 14.02.2016 / 17:34