Questions tagged as 'loop'

1
answer

How to create objects (variables) with different names inside a loop?

I want to generate separate databases in a loop. In the example below there would be 3 distinct bases with the following names: "data1", "data2", "data3". for (n in 1:3){ dados<-paste0("dados",n) dados<-runif(10,1,20)} However, wh...
asked by 06.03.2014 / 22:33
2
answers

What is the correct way to stop a "for" loop?

Let's say I have this for loop that works based on my array name: var nomes = ["Nome 1", "Nome 2", "Nome 3"]; for(i = 0; i <= 2; i++) { if(nomes[i] == "Nome 2") { console.log(nomes[i]); console.log("Stop!");...
asked by 12.05.2015 / 19:41
3
answers

Which loop is faster in C: while or for?

Being a loop while and a for that rotate the same number of times, which is faster? Example: while : int i = 0; int max = 10; while(i<max){ funcao(); i++; } for : int i; int max = 10; for(i=0; i<...
asked by 10.12.2015 / 19:00
2
answers

There is an "else while"

Is there any way for me to do this? While it's one thing to do that, then when is it another to do that? For example: var i = 0; while(i < 5){ //faça isso i++; } else { //faça aquilo } Is it possible to do this somehow?    ...
asked by 15.01.2018 / 12:15
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
4
answers

What would be a good way to apply events: onMouseOver and onMouseOut, for all img tag?

I need this function to be automated so that it applies to all images made on the HTML document without any exception Code function aumenta(obj) { obj.height = obj.height * 2; obj.width = obj.width * 2; } function diminui(...
asked by 08.02.2017 / 18:28
1
answer

What is the difference between 'for x in y' and 'Enumerable # each'?

We can iterate an Array / list in ruby in two ways: Using the for x in y syntax: > for x in [1,2,3] do > puts x > end 1 2 3 => [1, 2, 3] Using the method .each > [1,2,3].each do |x| > puts x...
asked by 17.02.2014 / 23:19
3
answers

For for incrementing in Python

I've learned that in Python , to loop% with for , from 1 to 10, we use range . More or less like this: for i in range(1, 10): print(i) Generally, in other languages, when we need to do a simple increment, we use the...
asked by 13.02.2015 / 16:03
1
answer

Concatenate Strings in Java Loops - StringBuilder or '+'?

Java allows us to concatenate Strings in Java using just the '+' operator String str = "a" + "b" + "c"; It's a simple way to do the job, and much less verbose than using StringBuilder. But in cases of Loops like the one below, which appr...
asked by 27.06.2015 / 14:53
3
answers

Algorithm language C - Multiplication

   Translate into the C language: Take a number from the keyboard and repeat the operation by multiplying it by three (by printing the new value) until it is greater than 100. Eg if the user types 5, screen the following sequence: 5 15 45 135....
asked by 09.06.2014 / 22:33