Most voted "loop" questions
Loops are a type of flow control structure in programming in which a series of statements can be run repeatedly until some condition is satisfied.
Learn more…671 questions
Sort by count of
-
6
votes1
answer177
viewsHow to reduce the number of loops to calculate the smallest difference between all the numbers in a list?
The program below returns the smallest possible difference between all the elements of a list: def calculo(A): r = float("inf") n = len(A) for i in range(0, n-1): for j in range(1, n): if abs(A[i] -…
-
5
votes1
answer363
viewsContinue running the loop even if a passage gives problem
I’m downloading Bovespa’s stock data for the package quantmod. However, I still do not know why, in the data from Santander (SANB11) the function getSymbols package is giving problem and loop for…
-
5
votes1
answer322
viewsCreating a matrix with variables with different correlations in R?
I need to generate data series that have correlations defined using R. I used a method I found here in the OS (How to generate correlated variables in R?) and I was able to create the variables with…
-
5
votes5
answers7269
viewsUse if inside foreach
I’m trying to change the order in which the results appear within a loop using foreach. What I need is for the numbers larger than five to appear first, followed by the rest of the numbers. So I…
-
5
votes2
answers183
viewsHow to insert a header to each N records?
How can I enter a header for each N records? Type ... <h1>CABECALHO</h1> Cadastro 1 Cadastro 2 Cadastro 3 Cadastro N <h1>CABECALHO</h1> Cadastro .. Cadastro .. Cadastro ..…
-
5
votes3
answers10282
viewsHow to navigate a children and a div with Javascript?
I need a function that goes through #paicasas and leaves the background of all children "casa1,casa2...". I tried to do it but I know it’s far from right. function apagar(){ for(var i in…
-
5
votes1
answer261
viewsReverse results of while
Is there a function in PHP that allows me to reverse the order of a result while? For example, I have the following code that checks whether a URL. <?php function url_exists($url) { $ch =…
-
5
votes1
answer1502
viewsWait to finish the thread before ending the program
I have a loop while that ends only when I press the key q, then the program is closed. Within that loop, at a given time or condition, I initiate a thread that takes about a few 10 seconds to run.…
-
5
votes1
answer281
viewsIs it possible to use the "break" argument on a "switch" to interrupt a loop?
When I want to interrupt a loop of one for, while or foreach always use the break; within a if with the following structure: $teste = array(1,2,3,4,5); foreach($teste as $t){ if($t == 3){ echo…
-
5
votes3
answers1759
viewsCreate post on a wordpress and bring in other wordpress automatically
Options: Create a new POST on a wordpress-1, from another wordpress-2. or Everything that is created in wordpress-2 be "copied" to wordpress-1 or Create/Register a product in a store(site)-1, from…
-
5
votes2
answers540
viewsHow do I exit a loop by typing a specific value?
I need to make a program that multiplies the numbers informed by the user, and when it reports 0 (zero), the program shows the multiplication of the numbers typed. However, I am in doubt of how I…
-
5
votes1
answer2438
viewsA break within two for actually works as a continue?
If I happen to have one break within two for, as in the example below: for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { break; } { The break won’t make the show come out of both for,…
-
5
votes2
answers1182
viewsUsing For in Python
Python can only work with for' (loop) using a list? It is not possible only with an integer as in other languages?
-
5
votes1
answer13456
viewsHow to go through attributes of a JSON?
I’m trying to go through attributes of a json, I’m trying this way for (var i = 0, length = r.length; i < length; i++) { for (var i2 = 0,length = r[i].lenght; i2 < length; i2++ ){…
-
5
votes1
answer79
viewsbRasilLegis [ command "get DetailsDeputed"]
I need to collect the data of the deputies who were present in committees, positions, etc. However, I can only do this with one deputy at a time. It’s possible I can choose them all at once?…
-
5
votes1
answer64
views -
5
votes1
answer1089
viewsHow does the for(;;)work?
It’s probably duplicated, but I didn’t find it here on Sopt, and I don’t know how to Google. How the loop works for in that syntax? for(;;) { //... }…
-
5
votes1
answer115
viewsOperation with very large size lists
I have a code that calculates the area of the intersection between two polygons and for that I use lists to store the coordinates of the vertices of the polygons, however there are many polygons and…
-
5
votes2
answers812
viewsGet previous element in foreach
It is possible to take an element from the previous to current position using the repeat loop foreach? For example, whenever I need to take an element previous to the current position of the loop, I…
-
5
votes2
answers1750
viewsHow to create a for in R with the indexes of a data frame
If I have a date.: > dato<-as.data.frame(matrix(1:64,8,8,T))[-3,] > dato V1 V2 V3 V4 V5 V6 V7 V8 1 1 2 3 4 5 6 7 8 2 9 10 11 12 13 14 15 16 4 25 26 27 28 29 30 31 32 5 33 34 35 36 37 38 39…
-
5
votes2
answers645
viewsPassing a variable within a precedent
I have this project procedure DocumentComplete(ASender: TObject; const pDisp: IDispatch; const URL: OleVariant); Now I need to use it in a loop by passing the count variable. I tried it as follows:…
-
5
votes2
answers214
viewsApplication of the `assign` function in loops
I want to play names in variables with a loop. With for I can get: library(tidyverse) for(i in 1:6){ names<-str_c('var',i) assign(names,runif(30,20,100)) } But with lapply and map nay: lapply…
-
5
votes1
answer181
viewsHow to parallelize on multiple levels in R?
I’ve been researching how to parallelize for in R and found the package foreach, which, from what I understand and correct me if I’m wrong, replaces the for as follows: library(foreach) vetor <-…
-
5
votes4
answers169
viewsWhich way can I use regular expression to capture just a few link attributes
I need a basic example(s) of how I can make a tiny script to pick up only the contents of(s) attribute href. I’ll simplify the explanation into two groups, it’s them: To and B In the Group A we have…
-
5
votes1
answer117
viewsLoop Error in R
I created this loop: library(forecast) a=1 b=60 while(b<=(NROW(tsarroz))){ janela=dput(tsarroz [a:b]) serie=ts(janela,freq=6) HW=HoltWinters(serie) prev=forecast(HW,6)…
-
4
votes2
answers263
viewsLooping an array to always choose the next value
I have an array of users and need to make a looping between them. It will work like this, every time someone makes a request on the page, I need to be recorded in the database the next user of what…
-
4
votes8
answers481
viewsI can’t learn syntax for
I can learn subjectively for a few seconds, but I can’t fix it no matter how hard I try. I’ve already repeated classes, I’ve done exercises and everything, but the syntax and its variations just…
-
4
votes1
answer158
viewsWhy does Facebook’s XHR request have that code?
I was analyzing the XHR requests from Facebook for study purposes and came across a code that I found curious to say the least. On the link similar to this 4-edge-chat.facebook.com/pull, has the…
-
4
votes2
answers106
viewsData window moving in time (t)
I want to make a recursive prediction. I need each month (t) to move the data window of the last month forward in a period (monthly period, that is, t+1).…
-
4
votes4
answers2080
viewsHow to capture elements in a json structure using javascript
I need to get some elements inside a JSON structure with Javascript. I can get unit elements like this: alert(response.paymentMethods.CREDIT_CARD.options.MASTERCARD.images.SMALL.path);…
-
4
votes1
answer76
viewsI can’t run code after the cycle is
I am using Selenium as Crawler on a website. I have no experience with python. Here I create a dataframe with the data of a .csv df = pd.DataFrame.from_csv( 'tabela_etickets_copa3.csv', columns =…
-
4
votes3
answers633
viewsLoop variable declaration error
I made the following command: for(int i = 1 ; i <= 3 ; i++) {etc } Then it made the following mistake when I went to compile: game.c:11:2: error: "for" loop initial declarations are only allowed…
-
4
votes2
answers1104
viewsShow an object/variable with different names in R?
Considering the following routine: x <- 1:10 for (i in 1:length(x)) { ## Nome da variável: nomevar <- paste0("Var_", i) var <- x[i] + 2 assign(nomevar, var) print(nomevar) # aqui esta minha…
-
4
votes1
answer1956
viewsWhile timer in Python
How to make a timer in while? I would like to run a while, and do something, e.g. a print "hello" run print "hello" for 1 hour for example.
-
4
votes3
answers216
viewsWhy is there an asterisk left?
I want the number of rows and columns to be equal to input data. Why is this last *? Code: #include<stdio.h> #include<math.h> int row = 0; char column = 0; int n; int main ( void ) {…
-
4
votes2
answers649
viewsDelete files created more than 10 days ago, saving the latest if everyone from the list has more than 10 days of creation
I did this question where doubt was how to delete files with more than 10 days of creation. I recover them from a directory and the code has already been implemented and is functional. However, I…
-
4
votes1
answer120
viewsLoop duplicating entire table
I’m not getting to make a loop in the table, it’s making loop to every bank search. $dbc = mysqli_connect('senha_adm'); $query = "select carro, barco, aviao, moto, triciclo, velotrou, dataCadastro…
-
4
votes1
answer283
viewsHow to get different outputs (fasta) files with Unix or python
I have a fasta file that has several sequences of genes, like: >gene1 C.irapeanum 5.8S rRNA gene CGTAACAAGGTTTCCGTAGGTGAACCTGCGGAAGGATCATTGATGAGACCGTGGAATAAACGATCGAGTG >gene2 C.irapeanum 5.8S…
-
4
votes1
answer516
viewsWhat does & Python mean? What is your name? is an operator?
I was looking over the loop while in Python, and everything was going well, but suddenly I see: "&", that even searching I could not find anything about. i = 0 while i < 5 : print(i) i =…
-
4
votes1
answer438
viewsPython remover() list index out of range
def gera_huffman(simbolosOriginal, probabilidadesOriginal): # gera_huffman(['a', 'b','c', 'd'], [5, 2, 1, 2]) simbolos = simbolosOriginal probabilidades = probabilidadesOriginal lista = [] while…
-
4
votes3
answers2418
viewsHow to make a rectangle of asterisks using for?
To solve this exercise: Write a program that prints a rectangle of n x m asterisks, in the which values of n and m are provided by the user. For example, for values of n = 5 and m = 7, the expected…
-
4
votes1
answer112
viewsProgram enters infinite loop
My goal with the code was to put together a game that asked the person what number the computer would be "thinking" (from 1 to 100), and as the person said a number from 1 to 100, the computer said…
-
4
votes1
answer175
viewsHow to loop to generate graphics in R?
Consider the following Data Frame: ITENS <-c("A","B","C","D","E") Q.1 <-c(10,20,10,40,10) Q.2 <-c(5,25,0,50,10) Q.3 <-c(15,20,5,40,10) Q.4 <-c(15,30,5,30,5) Q.5 <-c(20,25,5,20,15)…
-
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
answer3554
viewsHow to make a Bruteforce in Python?
I’m trying to create a Bruteforce program that can generate passwords with a size x of characters. The problem is that I can’t develop a logic for this. See my code below: chars = getAllChars() #…
-
4
votes1
answer81
viewsWhat is list comprehension? Control structure? Loop?
Some languages have a way to create other lists without needing high-order functions like map and filter. This form is called list comprehension, or comprehensilist on. It is common to see list…
-
3
votes1
answer168
viewsHow to vary parameters of an equation?
For an equation of the type y = ax + b, we have two values for a and two to b, That is, we have four different equations. We already have a code that returns us the values of x and y for each…
-
3
votes4
answers9378
viewsAlgorithm Factorization in C
I need to create a program in C, which factors in any number the user enters. I wrote this code, but it doesn’t work completely because it only calculates once. I don’t want an answer ready, I want…
-
3
votes2
answers1596
viewsForeach is returning only one record
I have a problem with my code. I have the following code: <?php require('class/habeo.class.php'); $Habeo->DuplicateRegister('contatos', array('id'=>'1', 'id'=>'6')); ?> This class…
-
3
votes2
answers125
viewsHow to loop with regex in javascript?
Hello everybody all right? I’m cracking my head on the following question: I have a string set: var teste = blabla 555.. 999 I have double white space between the digits and did the regex: var str =…