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
-
3
votes1
answer118
viewsData from Firebase takes a long time to complete loading and hinders sorting objects
I’m trying to sort an object by a value that comes from Firebase. I use a Jsonparcer class to list the database and according to the ID take the field I need in Firebase, which in this case is a…
-
3
votes3
answers757
viewsIs there a command or function in Javascript that controls the screen update before the loop ends?
Just one example: <script> for (var i=0;i<10;i++) { //Inicia loop for para contar de 0 até 9 var t=0; // inicia variável t com valor 0 while(t<1000000) { //inicia loop enquanto t for…
-
3
votes2
answers1637
viewsHow to print 4 triangles patterns next to each other in Python?
I need to write a program that prints 4 triangles patterns, one next to the other, separated by three horizontal spaces, as in this image below: To solve this, I wrote the following code: for i in…
-
3
votes2
answers129
viewsLoop Operation with Multiple Data Frames
Assuming the following example in R: Sample_data <- data.table(code = c("AAPL","AAPL","AAPL", "AMZN","AMZN","AMZN", "MSFT","MSFT", "GOOG","GOOG","GOOG", "FB"), date =…
-
3
votes1
answer34
viewsTransform 3 similar functions into one
In my project, I have very similar functions, with the same intention, however, as it is a DOM class exchange function (classList.replace), I ended up making a very repetitive code, and I’d like to…
-
3
votes2
answers107
viewsUsing do/while in Javascript to request 10 numbers from the user
My teacher passed an exercise with the following description: Make a Javascript program that asks for 10 integers and displays how many numbers are greater than 50 - use loop do while. I couldn’t…
-
2
votes3
answers830
viewsLoop in R with indexing and matrix
We’re trying to use the command for to run a y function (say y=5+3x+4z) varying the values of z (let’s say z is a combination of 5 values z=c(1,2,3,4,5)) and that x is a normal distribution of size…
-
2
votes2
answers1830
viewsPerformance in Java repeat loops
What is the difference in performance between the three types of ties highlighted below. List<Foo> list = new ArrayList<Foo>(); for (int i = 0; i < list.size(); i++) { //CODE } for…
-
2
votes1
answer1279
viewsHow to use FOR for INSERT within a function in ORACLE?
I have the following function: FUNCTION PERSISTIR_CR( p_AnoExercicio TB_CONFIGURACAO_EXERCICIO.NUM_EXERCICIO%TYPE ,p_CodCR TB_CESTA_ROTINA.COD_CESTA_ROTINA%TYPE ,p_CodUG TB_CESTA_ROTINA.COD_UG%TYPE…
-
2
votes1
answer250
viewsApplying Loop to Elements of a Matrix (R)
Be the matrix below created from the Command simu_matrix <- matrix(runif(25,0,1),nrow=5,ncol=5) V1 V2 V3 V4 V5 1 0.07357303 0.45524021 0.9352829 0.60466424 0.4725541 2 0.51018615 0.46044203…
-
2
votes0
answers209
viewsLoop to affect all records in a table
I wanted you to help me on the following, I wanted to execute the code that I’m going to show you below on a button so that I would do it automatically when I click on it. The program works like…
-
2
votes2
answers2256
viewsBreak line after semicolon ;
I have a text file (word) composed of four pages with several email addresses on each side separated by comma and dot. Is that way: [email protected]; [email protected]; [email protected];…
-
2
votes1
answer83
viewsConsult with INNER JOIN and choose the loop reference
Guys, I’m looking at two tables with INNER JOIN thus: if (! $db->Query("select * from cad_produto inner join cad_variacoes on cad_variacoes.id_produto = cad_produto.id")) $db->Kill(); while (!…
-
2
votes1
answer6018
viewsWhat are the differences between the repeating structures while, repeat and for?
Friends, I am learning programming logic and this doubt came when I should use these commands and their differences.
-
2
votes1
answer4199
viewsHow to stop a loop using the input provided by the user?
I’m writing a program that receives entries and creates a dictionary from them. I need the loop I use to insert the entries in the dictionary to be broken when the entry is "9999", but it is not…
-
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
votes1
answer496
viewsButton Loading 3 more posts
I’m wanting my button id="boot" (<div id="boot">) each time it is pressed, charge +3 testimonials. <?php query_posts( array ( "category_name" => "depo" )); if (have_posts()) : while…
-
2
votes1
answer646
viewscomparison using characters in c
Okay, the problem is only in function q31 and q311. http://pastebin.com/8CJwKej4 I left the complete code on the link above. then here is this function q311: void q311(){ char forma; int…
-
2
votes1
answer4995
views -
2
votes1
answer234
viewsPrint all results of a vector with a given value
I am starting the studies in C. I have a question of how to go through a vector looking for a value and print showing with printf all values found. The program I’m doing:…
-
2
votes1
answer588
viewsDelphi - Make a Thread that plays a song in a loop
I managed to make a Thread that plays the song, but only once. If I put a loop on it I have several errors, like the 1400. It seems that the thread does not close when you close Form1, because the…
-
2
votes3
answers1751
viewsReceive Json array and insert into a loop with HTML
Good evening, I’m using phonegap to make an app and then I get the following problem: I have this code in HTML: <div class="content"> <article class="underline"> <a…
-
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
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
answer47
viewsHow to mount this effect with JS?
I have a list, and I would like to create a loop by passing each of these elements, basically what I want is this effect: $.each($('.elemento'), function(i, el){ $(el).fadeIn(100);…
-
2
votes1
answer2649
viewsHow to calculate 2 n and (2 n)+1 in java?
I am doing a work in which I have to do some calculations with batteries and I need to do tests for powers of two and powers of two plus one, namely 1, 2, 3, 5, 8, 9, 16, 17, etc. The power of two…
-
2
votes2
answers127
viewsLoading Grid data with Checkboxcolumn
I am creating a form to perform a registration for a product license. This form is used to record which solution a customer has. In the form to add a product just select product and the client. I am…
-
2
votes3
answers5527
viewsList in Python with non-repeated values without using set function?
How can I create a list from the sum of two previous without some value appearing repeated, without using the function set? Example: >>>a = [1, 2, 3] >>>b = [3, 4, 5] >>>c…
-
2
votes2
answers51
viewsHow to inform data in a vector
I’m not getting to report 10 student grades. import java.util.Scanner; public class exer { public static void main(String[] args){ Scanner scn = new Scanner(System.in); double[] N = new double[10];…
-
2
votes2
answers1825
viewsIncrement variable within a foreach
How do I make a variable increment within a foreach? foreach($adults as $adultos): $i = 1; echo "<strong>Quarto".$i++."</strong><br>"; echo "Adultos:".$adultos."<br>";…
-
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
answer1282
viewsLoops based on a flowchart
How do I write the code for a loop based on this flowchart? It has a do...while. Peeciso of a simple and direct response with nested loops.…
-
2
votes3
answers1265
viewsAsk for n python entries
I’m having a hard time with this exercise: "Do a program that asks n people your age, at the end the program should check if the average age of the class varies between 0 and 25, 26 and 60 and above…
-
2
votes1
answer479
viewsHow can I improve this loop that has one foreach inside another?
I’m making this code that has 2 foreach’s and carries 350 properties with more or less 3500 image links, I didn’t really call the photos, just the links, it all loads in half a second. The variable…
-
2
votes1
answer53
viewsWhy use Kernel#loop instead of Begin-end-while/until?
I’m making a Ruby repetition structure using the following structure: begin [código] end <while/until> [condição] But the Rubocop, which I use as a tool for linting, says I should use the…
-
2
votes1
answer295
viewsAccess sub-tables in a moon table
How do I read a subtable inside a table? I tried to return the value with the following function but it went wrong. name = {"Lowes", "Renata", "Titia", "Maria"} health = {} posx = {} posy = {} posz…
-
2
votes1
answer94
viewsDelete list item if directory does not exist
I have a list containing the path of some directories, I want to check if each directory exists, for this I use the os.path.exists(), if a directory does not exist, I use the method remove() to…
-
2
votes1
answer122
viewsCreating a Ruby Commitment Schedule
I want to create a kind of routine that Intercale time interval Example: 8:00 to 12:00 with 30 Minutes interval A sample of the code class Appointment < ActiveRecord::Base has_many :schedules def…
-
2
votes1
answer182
viewsdifferences between for...in JS and in Python
in the following code in Python... string = "abcd" for i in string: print(i) --------------- output: a b c d and in Javascript string = "abcd" for(i in string) console.log(i) --------------- output:…
-
2
votes1
answer71
viewsMonitoring with the R
I have a monitoring script and would like to run it every five minutes, there is some function that does this? for example: função (meu_script, repetir= 5 minutos) tried some functions with…
-
2
votes1
answer181
views -
2
votes1
answer512
viewsProgram that read 3 numbers with repeating structure with scanner class!
How do I make a Java algorithm that reads 3 numbers and averages? I know how to do it without repeating structure, but how to do it with repeating structure? Follow my code below, but do not have…
-
2
votes1
answer759
viewsWhat is a recursive method?
The variable resultado within the for is recursive? #include <stdio.h> int main(void) { int N,i; double resultado=0.0; scanf("%d",&N); for (i=0; i<N; i++) { resultado= 1.0 /…
-
2
votes1
answer39
viewsNested loops and incrementation
I’m studying Javascript by code house book and has a challenge involving nested loops, in which I have to draw this: * ** *** **** ***** ****** ******* Using this code: for(var…
-
2
votes1
answer496
viewsPython - Problem printing inside a loop
I have the following code Python, representative of the game Pedra,Papel,Tesoura. import random listChoices = ["rock","paper","scissor"] print("Choose rock, paper or scissor to play or write exit to…
-
2
votes1
answer172
viewsLoop Replace all string characters by python list character
What I want to do is take a string and for each character of the string walk type 3 positions back in the alphabet and replace in the string or create a new string Ex string = 'abcd' walking 3…
-
2
votes1
answer34
viewsHow to create a copy of an element, through its property
I want clone only images whose the attribute alt be "photo". Code var str = document.getElementById('A'); var clone = str.cloneNode(true); document.getElementById('B').appendChild(clone); <span…
-
2
votes1
answer5400
viewspq the while True loop accesses if and Else in sequence to every complete loop in that code?
#! /usr/bin/python3 valor = int(input("Digite o valor a pagar: ")) cedulas = 0 atual = 50 apagar = valor while True: if atual <= apagar: apagar = apagar - atual cedulas += 1 else: print("%d…
-
2
votes1
answer66
viewsForeach followed by another Foreach on the same line
It is correct to use a foreach followed by another foreach (as in the example below)? <?php if($nome1): foreach ($nome1 as $nome2) foreach ($nome2->nome3() as $nome4): ?> #code html…
-
2
votes1
answer127
viewsDoubt with loop for counter
I want to run this very simple loop: for i in range (1, 5): num = int(input("Digite um numero positivo: ")) if (num < 0): print("Você digitou um número negativo, tente de novo.") If the user…