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
-
0
votes2
answers59
viewsExplanation of how loop variable declaration For/In works
var meusDados = { nome: 'Bruno Coelho', email: '[email protected]', idade: 23 }; var dados; for(dados in meusDados){ console.log(meusDados[dados]); } Why declaring the variable given before…
-
0
votes0
answers123
viewsHow to generate multiple nested repeat structures with methods
need to generate several nested structures (26) wanted to know how to do this with methods pro code not get too big an example of the structure I need with 4 nested: public static void main(String[]…
-
0
votes2
answers99
viewsArray returns wrong value in java
I have a question about a college job. I can read with numbers, remove ";" and pass the values to the array while reading the file. However, when I try to access a position of the array outside of…
-
0
votes2
answers218
viewsGroup tags separated by PHP comma
Good morning! Next I have a doubt, and I’m not able to reach conclusion. I’m creating a field called tag where it serves to search for posts related to tag. In the bank it is completed as follows;…
-
0
votes1
answer55
viewsLoop for from index 1 java array
I have a function that makes a loop for in a String array. I need the loop to start from the index[1] of that array. But I’m not getting it. String arquivo[] =…
-
0
votes1
answer34
viewsProblem iterating an array in php
I have the following code. $array = array(1,2,3); $arr1 = array(3, 4, 5); $data = []; for($i = 0; $i < count($array); $i++){ $data["ca"] = $array[$i]; for($k = 0; $k < count($arr1); $k++){…
-
0
votes1
answer84
viewsPHP: Group data without using group_by
Does anyone know how to group data without using group_by in consultation? I need every 10 loop results (foreach), create a div, that is, 10 records within each div, I don’t care about the values.…
-
0
votes3
answers151
viewsDisplay success message once in for loop
I have the code: for ($i=0; $i < count($descricao); $i++) { $id_caixa_hoje = $linha['id_caixa_hoje']; $valor_formatado[$i] = abs($valor[$i]); $inserir = mysql_query("INSERT INTO…
-
0
votes2
answers768
viewsCommand "goto" creating infinite loop in "for" loop
I want to simulate a school database that collects name, math and physics grades and averages both for 5 students (defined in a string of struct). Any grade above 10 would be allowed, without any…
-
0
votes1
answer73
viewsGet the position of an Associative Array within another Array
I have this array of associative array’s: Array { [0]=> array(4) { ["nome"]=> string(35) "ACRILEX TECIDO 37ML AMARELO CANARIO" ["preco"]=> string(4) "1.65" ["quantidade"]=> string(1) "1"…
-
0
votes3
answers406
viewsPHP array that is not getting values
The goal of the exercise was to create an array of 20 numbers ranging from -100 to 100. I have to distinguish between negative and positive values. If it is positive I have to add the value in its…
-
0
votes1
answer82
viewsHow to pick variable and print several "<li>" according to the variable number?
I have a variable $abas = 4. I need PHP to make one echo in the variable number, in this case it would be 4. The result should be: <li>1</li> <li>2</li>…
-
0
votes1
answer109
viewsHow do I calculate the percentage of the right number of answers?
Good, I think I have already achieved what I wanted to thank everyone my only doubt is whether a new number is generated every time the user enters a new guess,here is the new code: System . out .…
-
0
votes1
answer112
viewsNodejs - Expect for to run all pool.query by the end
I have a small problem and as much as I have tried to find a solution, I cannot think of a great one. So I have come to ask for your help! So here’s the thing, I’m currently developing a betting…
-
0
votes3
answers1982
views"for" with step "float": Typeerror: 'float' Object cannot be Interpreted as an integer
I want to loop 0 to 100 with step 0.1: for x in range(0, 100, 0.1): a = cos(radians(x)) But I get this mistake: Typeerror: 'float' Object cannot be Interpreted as an integer How can I make a loop…
-
0
votes1
answer139
viewsJavascript function inside a Loop For PHP
I have a JS function to hide/show table row, the same is inside a loop for. However I’m having difficulties to activate it. When I run such a function outside the loop it works perfectly, but when I…
-
0
votes3
answers75
viewsHow to calculate a FOR for 6 in 6 increments it give an echo?
I have a simple FOR that I need that every 6 increments it sends an echo with a message, follows code: $carros = array("Volvo", "BMW", "Toyota", "Alfa Romeu", "WV", "Teste", "test2", "Teste4",…
-
0
votes1
answer34
viewsNext element of the loop
I’m trying to implement a commit search algorithm between two tags with the command git log tag1...tag2. For this I used the command git tag that returns me the tags of a repository. With this…
-
0
votes2
answers448
viewsAlgorithm problem over percentage
I had to do this algorithm : In 2010, a small Brazilian city has 20,000 inhabitants. The forecast of IBGE is that this city grows at a rate of 5% per year. Knowing of this, make an algorithm that…
-
0
votes1
answer91
viewsHow to pause and continue after an event a For?
I have that code here: function aparecer(){ const array1 = [1,2,3,4,5,6,8,9,10]; for (let i=0; i < array1.length;i++){ const lugar = document.getElementById('local'); const ul =…
-
0
votes1
answer80
viewsUpdate value using For each event
I have this code here: var current = 0; var array1 = [1,2,3,4,5,6,8,9,10]; function aparecer(){ //verifica se o current é maior do que o array if ( (array1.length - 1) < current ) { alert("oi");…
-
0
votes2
answers402
viewsPHP - array shuffle
I’m programming a page of feed on news in PHP. I ask for your help to help me shuffle the array $tagsArray for posts not always stay in the same order. Thank you in advance! Code: <?php $conexao…
-
0
votes1
answer37
viewsThe difference between FOR and DOSEQ in clojure
What difference between for and doseq? I wrote a program, which returns me the highest value within the parameters informed. Note: I know that there is a function max and max-key, but I don’t want…
-
0
votes1
answer49
viewsLoop "for" does not scroll through all list items
I have a problem with the following function: function limpaLista() { var lista = document.getElementById('resposta'); var itens = document.getElementsByClassName('Repos'); for (item of itens) {…
-
0
votes0
answers58
viewsCurl inside is time consuming and troubled
I need to test all user accounts of a db on text area am utilizando the script function informacoes(){ $linhas = explode("\n", $_POST['conta']); $count = count($linhas) -1; for($i=0 ; $i<=…
-
0
votes2
answers218
viewsfor in range no flask template
I’m in doubt, the API I’m getting returns me two data types "ID" and "Title" are several id and title and I wanted to play this on my table in a "for" template. I wanted to know if what I did was…
-
0
votes1
answer102
views(JAVA) Error in foreach
Why is there an error in executing the code below if I remove the break? The value of Arraylist clients is not updated every time it ends? for (Cliente cliente : clientes) { if…
-
0
votes1
answer45
viewsCycle for only runs once inside a while and should always be run
listaA = new ArrayList <>(); boolean n = true; while (listaA.size() < listab.size()) { Log.i( "while ordena" , String.valueOf( listaA.size() )); valorAl = nRandom.nextInt( listab.size() );…
-
0
votes3
answers906
viewsHow to run the loop for 2 in 2?
My solution: function passandoPelosPares() { for (var i=0; i <=6; i++) console.log ('aqui eu tenho o valor de' + i) } Reply 'insufficient': Print out passandoPelosPares() must print: aqui eu…
-
0
votes2
answers76
viewsHow can the end of "for" be a user-defined variable?
In a for in C, we define "beginning, end and step increment". I know that in Python it is not so. I saw that it is called foreach. I wish the end of mine for is defined by the user. And that, at…
-
0
votes0
answers35
viewsHow to enter a number (x) and add up all the previous numbers?
How to enter a number and make the sum of all previous numbers, EXAMPLE: I enter the number 5, it will add up to 0+1+2+3+4 = 10 ! He will add and give the answer. I have to use the FOR command. My…
-
0
votes1
answer156
viewsHow do this FOR (in C#) list only the first five items?
I have an orderly list, which I need to display only the first 5 items, not all bank records, so I’m not getting it. Here’s my code as is: public class DashboardController : Controller { private…
-
0
votes0
answers122
views"SIGSEGV ON THREAD", can someone help me to solve, and also, if possible, to complete the program?
Here’s the thing, I do an info tech, and I’ve been learning C for just two months, and I don’t know much yet. Recently my teacher asked me to make a program in which user entered with two numbers…
-
0
votes1
answer35
viewsshow the value of the child inputs of Divs js
I need the for/while to show on the screen the string placed in the input of the first div the first time the loop is executed and the second time to show on the screen the string placed in the…
-
0
votes1
answer46
viewsIs it possible to loop with "0" on the left in PHP?
Dear Devs, I’m trying to use a list with zero left using for and str_pad, but I’m not getting the variable with 0 left, the first variable comes complete but in the autoincrement it’s counting…
-
0
votes1
answer280
viewsEven numbers in an array with for - PHP
Hello, I would like to understand where my code is wrong. I need to filter only the even numbers of the array using for. But it returns the following answer to me - "The filter is not working very…
-
0
votes1
answer119
viewsHow to place a countdown in more than one post on the page?
Good morning! I have the following problem, I have the view below that works as a schedule, within it I have some publications. I can get to each of the posts and get the amount in minutes left to…
-
0
votes0
answers40
viewsLoop process error using for
Hello I would like the help of you, to try to solve the following problem, I created a script that allows to take the direct link of an online video upload host, the process works, but I do not know…
-
0
votes1
answer509
viewsSort vector from smallest to largest
PHP: array_push($var, $linha['data']); array_push($var, $linha['data_t']); array_push($var, $linha['data_f']); usort($var);// Adicionei essa linha para tentar formatar as datas da menor pra maior…
-
0
votes1
answer95
viewsHow to scroll through an array the right way
Good evening guys, I’m having an immense difficulty regarding arrays... I have the following array: array(6) { [0]=> array(1) { ["cep"]=> array(2) { [0]=> string(8) "15070650" [1]=>…
-
0
votes0
answers82
viewsSave loop for data to database
Good morning I am developing a financial part where I fill out a certain form which is due date, full amount, discounted value, school year, percentage of the discount and amount of portion however…
-
0
votes2
answers153
viewsWithout the if explanation
As far as I know, else should be below the if, corresponding it, but in the code below, Else is not next to the if , because it is outside the repeating structure, to be more exact, the else is not…
-
0
votes0
answers39
viewsWhy isn’t my condition giving me the expected result?
I’m performing a line break without using the function wordwrap(). I will receive a string with the text, and an int with the allowed character length per line as parameter. I will have to cut this…
-
0
votes1
answer61
viewsHow to sort items from a list using two different values?
I have a list, which contains several values, each group of values corresponds to an audio of a language, however I am not able to sort using two conditions. audio_list = [{640: 640, 'lang': u'en',…
-
0
votes1
answer44
viewsHow to look for a value within an arrangement
I need to write a function that gives me a list of the name skills in the console input.log ms can’t understand this for-of. I’m a beginner in javascript and since yesterday I’m jumping from article…
-
0
votes1
answer34
viewsGo adding for values in the array
I created an array: var tagListArray = []; for(i = 0; i<resultados.item(i); i++){ tagListArray = ["valor1", "valor2"]; } console.log(tagListArray); That one resultados.item(i) me returns x…
-
0
votes1
answer34
viewsRepeat number at each count
How do I do this in php, please help me: ( Every three times ) 0 = 0 1 = 0 2 = 0 3 = 1 4 = 1 5 = 1 6 = 2 7 = 2 8 = 2 So on and so forth. This is a simple example of what I would like to do, because…
-
0
votes2
answers60
viewsIs there any way to use methods within other python methods?
I wonder if in Python it is possible to create a loop for within a format()? Example #Considerando: z=(1,2,3,4) print(f'''os números pares foram { for i%2==0 in z: print(i,end='são números pares')…
-
0
votes1
answer59
viewsAJAX request with FOR
Good staff as I can correctly print Hello World, using AJAX request, inside a for? My real question is: understand why the for executes your entire loop in the first ajax request, and only then run…
-
0
votes2
answers127
viewsDifficulties with the FOR command in Python
I’m putting together a program that reads information about angles and distances from a text file and draws according to the information contained there. The program should also calculate azimuths,…