Most voted "for" questions
Use this tag when the question primarily involves logic and/or command structure. Effectively, the for is a loop of repetition used to iterate matrices, vectors, or to another end that basically has three components: start, stop condition, and step, where it is usually possible to omit some of these components (although not very recommended).
Learn more…446 questions
Sort by count of
-
4
votes2
answers101
viewsHow to make a loop/routine for the write.fst() function?
I have the following files in my working directory: Dados_1.fst Dados_2.fst Dados_3.fst Dados_4.fst ... Dados_10.fst The Dados_x.fst file (where x goes from 1 to 10) has the columns CODIGO,…
-
4
votes1
answer76
viewsArray Ordering with Value Exchange
Good Afternoon! I have assembled an array that receives 9 records from a single variable and the values are displayed on the user screen. However, when trying to put this matrix in ascending order,…
-
4
votes1
answer220
viewsHow to add 1 to the number using the "for" command when the number N is a function parameter?
Being n the value of 5, adding up 1 + 2 + 3 + 4 + 5, resulting in the return. I tried to do it like this, but it didn’t work: function (n){ for ( var i = 0; i < n.length; i++ ){ total += n[i]; }…
-
4
votes5
answers3418
viewsCheck the amount of negative elements in a JS array
I am initiating Javascript studies and I come across a question where I need to identify negative elements in an array and return the amount of these numbers. Remembering that there may be empty,…
-
4
votes2
answers253
viewsIs it OK to use a switch inside a for?
Came to me a question related to the use of a switch within a for. I saw that it works for my purpose but this is correct to do in the world of programming? There is a better way to get the result…
-
3
votes1
answer408
viewsVar inside the FOR when starting at 0(zero) Count should be Count-1?
I picked up a system at the company where I work for another colleague. I note that all FOR’s are like this: for(int i = 0; i < lista.count; i++) { //meu código } I learned that when a variable…
-
3
votes1
answer633
views -
3
votes1
answer29
viewsremove php display item
I have a problem here, I know it can be simple, but I still can not solve alone. I have a slide spinning in a loop of PHP, in this slide there are "entities" that when the expiration day comes they…
-
3
votes1
answer50
viewsWhy does the for-loop convert from Date to integer?
Can anyone explain why in for-loop the objects Date are converted to integer? In the code below I want to iterate on the dates but these are converted to integers. > dates <- Sys.Date() + 1:10…
-
3
votes1
answer559
viewsI’m having trouble displaying the names of people over 18
/*Escreva um programa que receba o nome, profissão e a idade de 10 pessoas, calcule e imprima a quantidade de pessoas maiores de idade (idade >= 18 anos) e seus respectivos…
-
3
votes1
answer180
viewsVariable with unassigned value within a "for" loop
int i; string cpf; cpf = "11111111111"; DbConnection cnx = ADO_Utils.GetConnection(); DbCommand cmd = ADO_Utils.GetComando(cnx); cmd.CommandType = CommandType.Text; for (i = 1; i <…
-
3
votes3
answers94
viewsHow to reference the first loop from the second in a chain of loops?
In PHP, how can I reference the first for from the second, as in the example below? for ($i=0; $i < 10; $i++) { for ($j=0; $j < 10; $j++) { // Quero que esse afete o primeiro `for` e não o…
-
3
votes0
answers70
viewsHow do I separate my arrays by Dice?
Text boxes corresponding to the number that the user entered are generated, each text box is accompanied by several checkboxes to choose the type of text. But it comes out like this : Array ( [0]…
-
3
votes1
answer3361
viewsLoop for inside loop for
for(pass = 0; pass < size - 1; pass++){ for(j = 0; j < size - 1; j++){ if(array[j] > array[j + 1]){ swap( &array[j], &array[j + 1]); } } } I put only a piece of code where I have…
-
3
votes1
answer300
viewsCan I place two conditions/increments within the same loop?
I want to basically do this for (j = parametro, int k=0; j < parametro + 3, k<3; j++, k++) { previsoes[i] += valores[j] * pesos[k] ; }
-
3
votes1
answer429
viewsMore than one list in the same loop
I can put more than one list on it loop? for example, you can put more than one variable in a for: for (int a, b; a<10 b<20; a++ b++) { ....... } So I wanted to put more than one list on it…
-
3
votes3
answers138
viewsIs it possible to use for loop to reduce C code?
I have the following function:To. It is possible to use for loop B to generate the declarations as in the function To? What to wear instead of printf to become a declaration?…
-
3
votes0
answers35
viewsThe Handle function is not converting - Matlab
Hello, I’m getting this mistake: Conversion to function_handle from double is not possible. I have already searched for the bug and tried to change the code but without success. Could you give a…
-
3
votes2
answers97
views -
3
votes2
answers1405
views -
3
votes2
answers186
viewsRun command for each column of a date.frame
Hi, I have a data.frame (df) 8 rows x 8 columns. I am calling the columns "ST[i]". df <- structure(list(ST1 = c(58.69, 58.5, 58.5, 58.69, 58.69, 58.5, 58.69, 58.69), ST2 = c(68.7, 68.42, 68.42,…
-
3
votes5
answers6310
viewsHow to stop the end='' command in Python
I got a problem every time I use the remote end='' he does not stop! Example: tabela = ('Palmeiras', 'Flamengo', 'Internacional') for time in tabela: print(time, end=' ') print('=-' * 20) Execution:…
-
3
votes1
answer85
viewsArray always getting the same value [Loop in two matrices simultaneously]
My program scans an image and assigns color values R,G, B the variables that were compared with matrices containing the colors R,G, B asphalt and earth called auxAsfalto and auxTerra. The point is,…
-
3
votes1
answer62
viewsFill date.frame using for output
I wanted to know how to apply the logic of R to Python. For example: If I enter the code below in R: x <- data.frame() for (i in 1:10) { x[i,1] <- i } It will create in the date.frame x a…
-
3
votes1
answer99
views"For" 'lagando' interface
I have a JSON I’m using to generate an HTML in a app Cordova as follows: function gerarLista(lista) { strHtml = ""; for(item in lista) { strHtml += '<div class="item">'; strHtml += '<div…
-
3
votes3
answers964
viewsCalculate change and display available notes with Javascript
I have a class activity to do, where I must receive from the user the amount of the purchase and the amount paid, and then display the change. So far ok, only it also asks to display in a textarea…
-
3
votes3
answers4717
viewsI need to write a suit functionDeruco, that given a suit, returns a list of strings, one for each card of this suit following the cards of the truco
TIP: The cards include all numbers except cards 8 and 9. The reasoning I had at first was to create several arrays each with the suit name (spades, clubs, diamonds and hearts) and then use the FOR…
-
3
votes3
answers95
viewsDifference between creating a list with each iteration and using a list comprehension
I need to calculate the distance between the points (0,0) and (1,1). For that, I wrote the following code: def distance(x, y): if len(x) != len(y): return "x and y não possuem o mesmo comprimento"…
-
3
votes3
answers179
viewsBasic Python repetition - doubt in "and" and "or"
Hello, I’m learning Python. A question arose in a repetition exercise (for). The exercise is to identify all odd numbers and at the same time multiples of 3, in the range of 0 to 500. The solution…
-
3
votes2
answers28
viewsCommand to create multiple columns in a data.frame conditioned to other 2 columns
If I have a date.frame formed by the vectors: V1<-c("A","B","C","D","B") V2<-c("C","D","C","B","B") V3<-c("D","D","C","A","A") V4<-c("C","B","C","A","C") G1<-c("C","C","A","A","B")…
-
2
votes1
answer122
viewsTie problem for
I’m having a problem and I can’t identify it in my code, I have a for with 60 iterations, and it’s falling in if’s when I identify it (i in this case) is divisible by 5 or 3 only in the first…
-
2
votes1
answer205
viewsHow to script auto-complete/increment
There was a need to create a text field that would receive names of cities, however complete the word in the field when starting the first digítos. I need some idea, function with Arrays literals,…
-
2
votes2
answers452
viewsLogic PHP: how to build this looping (for, while, foreach)?
Good night. I am in the following situation: I am reading an XLS and playing in table. This XLS has 52 rows and 6 columns. What I’m picking up to do is: $result[linha 1][coluna A] $result[linha…
-
2
votes1
answer158
viewsSimple doubt about for loop
I have 4 images: one image on the other inside a div. It’s on top of each other because it’s in position absolute. I’d like to make a slideshow simple, just to learn its basic functioning within a…
-
2
votes2
answers186
viewsConvert File Names to Alphabet Letters
Convert File Names to Alphabet Letters For example, I have several image/photo files in a directory, and I want to pass these long names of the respective images in names designated by letters of…
-
2
votes1
answer326
viewsHow do I stop a for loop that stores the values of strings typed in C++?
So I’ve tried everything I’ve tried to compare type typed a "." or set a limit value and even then the program does not continue, it stays inside the infinite loop. The code comes next:…
-
2
votes1
answer59
viewsHow to read a file if its name is stored in a variable?
I have a file with names of other 980 files actually, so I wanted to read that file and go storing the names in a variable and then open the file with that name, I tried with read table but as the…
-
2
votes0
answers77
viewsWhy does it only work as expected the second time?
I have that function: for (var i in chars) { chars[i].walk(); for (var j in chars) { if (i != j) { collision(chars[i], chars[j]); action(chars[i], chars[j]); } } } Does it work in an unexpected way…
-
2
votes1
answer122
viewsCreating String Paging with Javascript
I’m creating a code for how to paginate the contents of a new String(); using Javascript, notice in advance, which is a runtime pagination compared to a pagination performed by ASP or PHP. It…
-
2
votes1
answer614
viewsHow do I return the total sum of the repeated words within all div?
To illustrate the degree of difficulty, I place 3 div and within them identical words, purposeful to add their duplication. <div> <div> <div> Diego Ademir Diego Maicon Diego Maicon…
-
2
votes1
answer193
viewsHow to present only even and odd values with three variables in C?
My variables are : int codigo; --> Sendo esta variável para o switch int numero1,numero2,numero3; User will enter with three variables : printf("Digite o primeiro numero inteiro: "); scanf("%d",…
-
2
votes1
answer10388
viewsHow to present only negative values in C?
I have three variables : int numero1,numero2,numero3; After you have declared them, I am asked the user to fill them in : printf("Digite o primeiro numero inteiro: "); scanf("%d", &numero1);…
-
2
votes3
answers160
viewsWhat is the logic behind this function?
Why the result of L1 is: [2, 3, 4] instead of [3, 4]? def remove_dups(L1, L2): for e in L1: if e in L2: L1.remove(e) L1 = [1, 2, 3, 4] L2 = [1, 2, 5, 6] remove_dups(L1, L2) print(L1) I tested in…
-
2
votes1
answer25
viewsproblems with Cycle for
I’m with a rather simple doubt, but I haven’t figured out the solution yet. I have this df: High Low Middle current 0.51 0.43 0.22 former 0.92 0.28 0.21 never 0.78 0.22 0.9 and I wanted the values…
-
2
votes4
answers191
viewsCan you make one simpler than that?
I don’t understand this decrease with the increment together. Read 2 integers I, F with I < F and check whether I is smaller than the F. Print I, F, successor to I, predecessor of F, successor of…
-
2
votes1
answer61
viewsIs it possible to convert this for loop to an apply family function?
df_loop <- data.frame(data1, data2, data3, 0) for (i in 4:nrow(df_loop[1])) { tmp_1 = df_loop[i,1] tmp_2 = df_loop[i,2] tmp_2_lag3 = df_loop[i-3,2] tmp_3 = df_loop[i,3] if (!is.na(tmp_2_lag3)) {…
-
2
votes2
answers62
viewsMATLAB - Data is lost when closing the FOR loop
I’m having trouble with a loop loop that counts the white pixels of a piece of an image and stores the position x and y of the piece and the total of white pixels. When printing the values within…
-
2
votes4
answers2189
viewsSum of primes in a range in C
My problem says to add the primes in a user-given range, including the ranges if these are primes. Example: ENTRANCE: 2 and 10 EXIT: 17 I managed to do that: #include <stdio.h> int main() {…
-
2
votes3
answers91
viewsSomeone can explain to me the following situation:
pessoa = { nome: 'leandro', idade: '2' } for(x=0;x<pessoa.idade;x++){ console.log('Ola mundo'); // ele repete 2 vezes "Ola mundo" na tela } The question I have is that I thought that Javascript…
-
2
votes1
answer324
views