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
-
2
votes3
answers17023
viewsDo while in python
Is there a similar command to while de c and Java in python? I am entering the language now and already developing in java then I got this doubt
-
2
votes2
answers103
viewsWhy is this loop infinite?
I wanted to stop the loop when t is at 5. So I counted -1, but it does not go back to while to check the condition and turns a loop infinite. text = 'abcdefghij' t = 10 while t != 5: for i in text:…
-
2
votes2
answers110
viewsDoubt with loop of repetition
I am doing a series of exercises in PHP for practice. And I came across a question regarding the loop of repetition. To explain better I will put the statement of the exercise here: Efetue um…
-
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
votes1
answer52
viewsHow to describe the execution of the loop for Javascript in Portuguese?
I am a beginner in programming, and I am in the instruction module of the course to which I study and I came across this code below in the double instruction of for. I understood in part how this…
-
2
votes2
answers2890
viewsLoop "for" inside another "for" (nested repetition)
I’d like to spare those 9 repeated lines in my code: for (int n1 = 1, n2 = 1; n2 < 11;){ Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//1 Console.Write(n1 + "x" + n2 + "=" + (n1 *…
-
2
votes1
answer2003
viewsLoop "for" counted odd number, even and average
I need to make a code that: List a number of numbers Inform if they are divisible by 3 and 5 Whether they are even or odd And then take the separate average of each (average of odd and average of…
-
2
votes1
answer721
viewsHow to join two tables using auxiliary table and LINQ
I have the tables People and Representatives, where in my application the person may or may not have representative(s). public class Conta { int PessoaID; string Nome; String Documento; } public…
-
2
votes1
answer50
viewsWhy doesn’t this code go wrong, but it doesn’t return anything?
I’m still learning Haskell (actually just started about 2 days ago) with a basic C# knowledge. In this piece of code the code is supposed to iterate several times in a list and subtract the first…
-
2
votes4
answers3559
viewsIncrement a counter within a php foreach
In a bow tie foreach I need to increment a counter to set the tabindex of the form fields, so that the result is: <input type="text" name="endereco[0][cep]" value="00000-000" tabindex="1">…
-
2
votes1
answer67
viewsCode in infinite loop
I developed the following código to take the content of a given web page: import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; Logger logger=…
-
2
votes1
answer170
viewsDoubt about echo inside a loop
I have this code for an API test and I wanted each end of the loop to write on the screen the progress of the script in %, but it only shows when it finishes doing everything, there is some way to…
-
2
votes1
answer175
viewsHow to get the number of lines from a Stringlist and apply?
I have a StringList inside a file mensagens.txt, I’d like to count how many lines there are StringList contained within that file. For each line of the string 1 code will be executed within the…
-
2
votes2
answers6045
viewsHow to ask questions for the user in Python, without running constantly?
I’m creating a code in Python that asks for the nick of a player and, as the user responds, he will receive a reply, check: player = (input('Digite o nick desejado:')) if player == 'Phil' :…
-
2
votes1
answer95
viewsJavascript loop for problem
I want the loop below is show all even numbers that are smaller or equal to it, but I can only make it show the last number. If I type 40 and it returns only 2. <div class="calculo"> <input…
-
2
votes3
answers85
viewsRepeat if again when validation fails
ConvInicial = str(input('Você: ')) if ConvInicial == 'Não estou passando bem' or ConvInicial == 'Estou com dor' or ConvInicial == 'Preciso de ajuda': print('O que você está sentindo?') RespDor =…
-
2
votes2
answers574
viewsItem limit in "foreach"
I have a code that picks up the images from the folder images/FotosdoWhatsAPP, but is displaying all images, would like to display only a quantity X (ex: 5 images). <?php $dirname =…
-
2
votes1
answer175
viewsExtracting data from a data frame in R
I have a data frame in R and the table has row sets with the same attribute (name of an instance) and different columns with data on each instance. INSTÂNCIA VALOR 1 VALOR 2 Instancia 1 10 20…
-
2
votes1
answer357
viewsHow to execute a synchronous request in a looping
In the example below let arr = [ { 3 : 'teste' }, { 5 : 'teste' }, { 1 : 'teste' }, { 2 : 'teste' }, { 0 : 'teste' }, { 4 : 'teste' } ]; arr = arr.sort( ( a , b ) => { return Object.keys(b)[0] -…
-
2
votes3
answers362
viewsHow to insert a new key associated with a new value at the end of a PHP Multidimensional Array
I have a multidimensional array with the following structure below: Array ( [0] => Array ( [id] => 1877 [type_id] => 4 [service_id] => 1100 ) [1] => Array ( [id] => 2299 [type_id]…
-
2
votes1
answer459
viewsVery slow recursive Fibonacci method, what is the cause?
I made a program with recursiveness, but when the user type 50, the processing to generate the Fibonacci sequence is now over extremely slow. Is it due to data input/output processing on the…
-
2
votes1
answer92
viewsHow can I make a repeat structure here?(Fortran)
program equacao implicit none real a,b,c,q real x3,x2,x1 character s,n,read,if complex sqrt 100 print*, "Esse programa calcula equacoes do 2 grau" write (*,*) "De os valores de a, b,…
-
2
votes1
answer51
viewsWhy R is not finding the created function
Before I had made an extremely large code to be able to extract the results I expected, but the code got quite slow and with that, I’m trying to optimize it: Previous code: Rent division…
-
2
votes1
answer380
viewscreate PDF dynamically in Rmarkdown
Good afternoon. For a week I’ve been trying to do a magic at Rmarkdown but I can’t. Well, come on. Contextualizing: I need to write different Pdfs (or html) with different contents. In this case,…
-
2
votes5
answers2164
viewsSquare root manually in Javascript
I’m trying to manually calculate square root in Javascript. Theoretically it was to stop at 100 according to the value that is in the variable number, but it continues to multiply. Code sample: var…
-
2
votes1
answer58
viewsDoubt with loop operations
I have this df: df_1 <- data.frame( x = replicate( n = 6, expr = runif(n = 30, min = 20, max = 100), simplify = TRUE ), y = as.factor(sample(x = 1:3, size = 30, replace = TRUE)) ) I would like to…
-
2
votes1
answer112
viewsCalling Loops dataframes in R
I have a series of data frames, which I will work on several times in some loops. The problem I find is that I cannot "call them" correctly to perform other actions, comparisons, etc. My code: list…
-
2
votes1
answer167
viewsLoop the loop after performing functions
I’m having difficulty in this code, I adapted in two functions as guided by prof. but I’m having difficulty in the final phase, which asks: use for or while n times (n is equivalent to the quantity…
-
2
votes1
answer104
viewsLoop with dataframes in ordered logistic regression
I need to estimate an ordered logistic regression in which the database is divided into 417 dataframes giving a total of 33.7 GB. Merging all subsets into a single dataframe would make the option…
-
2
votes3
answers342
viewsHow to make a sum in a loop for or while?
I need x to be added to 7 after the loop, but I’m not getting it, the code works perfectly if I do x++, is there any way to make that sum with 7? var x; for (x = dtdia + 2; x <= 31; x+ 7){…
-
2
votes1
answer60
viewsHow can I perform a function only once in a period of time
I wanted to know how to do a single execution, example: In my application there is a way to schedule charges and they are scheduled per day, then on a certain day X she will be charged. I’m…
-
2
votes1
answer66
viewsHow to save the generated graphics files (in png) within a loop
I’m trying to generate png files of graphics that are inside a loop. I tried to do with the function ggsave but I cannot insert inside the loop and outside the loop generates the empty file.…
-
1
votes1
answer1008
viewsSplit a table to optimize your page space
I have a array and with it I make a table with data comparison, this table gets very big (it has to roll a lot the scroll mouse) and on the right side of the screen is blank. Script: reset($quebra);…
-
1
votes1
answer250
viewsHow to create separate objects from a loop?
class linha (): def __init__ (self, texto): self.texto = texto def criador (): for i in range(5): a = raw_input ('escreva: ') global objetoi objetoi = linha (a) How do I make the function criador…
-
1
votes1
answer2993
viewsHow to loop a custom post type by following the menu_order?
On a static page in wordpress I’m looping a custom post type from a list of services as follows: $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query();…
-
1
votes1
answer412
viewsHow to manipulate Labels using a loop
How can I use these Abels using a loop instead of creating 40 lines of repeated code? jLabel1.setIcon(new ImageIcon(getClass().getResource("/cards/"+cards.get(1)+".png"))); jLabel2.setIcon(new…
-
1
votes2
answers1488
viewsDifficulty with for loop in Ruby
I’m having trouble dynamically displaying the content of variables. Ex: minha_var_1 = %{Um texto} minha_var_2 = %{Outro texto} minha_var_3 = %{Mais outro texto} But I’ve tried to show off so much…
-
1
votes3
answers1404
viewsInfinite loop when typing a character
I’m doing error tests on my "Monkey Test" program and it goes into loop infinite when I type a character on the keyboard other than number. int ActionGenerator() { bool Verify; int Action; Verify =…
-
1
votes1
answer116
viewsStop the loop when you find a result
public Objeto busca(String nome){ for(Objeto id : MinhaLista){ if(id.getNome().equals(nome)){ return null; } else { return id; } } } this is the code, it’s returning the id or null repeatedly. how…
-
1
votes1
answer717
viewsAvoid endless loop of errors
I would like to know if you can avoid the occurrence of infinite loops of errors in Delphi XE2. These errors are usually critical errors of missing some file (like DLL) or without permission to…
-
1
votes1
answer542
viewsStop accepting data to queue dynamically
I need to stop queuing when the user enters a negative number (-1), check if the queue is empty so that when typing the negative number does not give any error and the main one, I need the user to…
-
1
votes1
answer77
viewsGet last child of a product category
Everybody, good afternoon, everybody. I need to get the last child of a category within a product loop: Categoria -categoria filho --categoria ultimo filho It always gives me the Father, ie…
-
1
votes2
answers250
viewsRepeat loop is not running
I am making a code in which there is a vector (with 15 positions) with predetermined values (10 values any and 5 times the value 0), and where the user will inform a new value to go to the end of…
-
1
votes1
answer288
viewsCreate different random password for each loop record
I have a loop that you should enter a random password for each record, and when you finish the loop (have created different password for each record), list the results by viewing the password.…
-
1
votes2
answers87
viewsProblem with vector ordering
Good afternoon, I’m having a problem with a vector ordering exercise, I’ve reviewed the code, it compiles, but I’m not finding the error so the order does not get crescent, varying in certain parts.…
-
1
votes1
answer434
viewsCalling from the 2 post in the wordpress loop
I am making a loop in wordpress using Wp_query and need to list me only from the 2 post, ignore the 1 first post. In the past I used query_posts('offset') to do this, but using wp_query I’m not…
-
1
votes0
answers111
viewsLoop wordpress with colorful div
good morning! I’m setting up a gym website where there’s a menu of modalities. I made a custom post in wp to create the modalities, but my problem is time to call the modalities, because each…
-
1
votes1
answer46
viewsMake a loop for 2 cells by clicking
I need a loop for 2 Labels where each one appears a text already specified in the code. Just out of curiosity. I wanted a loop with the same effect as the code below: private void…
-
1
votes2
answers2392
viewsHow to make setTimeout run "infinitely"
I need a function run every 2 minutes. I found in this link a solution to my need: Link The Code below, calls an Alert after 5 seconds while leaving the mouse stationary. Observing I put 5 seconds…
-
1
votes1
answer1364
viewsAdd widget in an Array
I need to add lista.get(i) in an array, will be added in the array with the value of key spec_linha-criativa changed. However, in my code I always lose the reference and when j = 1 My list has the…