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
-
1
votes2
answers7697
viewsWrite each step of a factorial calculation
I have a piece of code that calculates the factorial of a number in Javascript, but I wanted it to return the steps of each calculation, ex: 3! = 1x2x3 = 6 Follow the code I made. I tried "printar"…
-
1
votes3
answers467
viewsHow to get an advanced "for" score?
I was wondering if I could get some kind of control variable, from a for "advanced". For example: In a be normal, I do it this way: for (int i = 0; i < algumaCoisa.size() ou length; i++){…
-
1
votes0
answers37
viewsFor is taking the rest of the sample variables in R
I’m making a sample and the size of it is in a spreadsheet called "sizing". When I use the command is, as below, the sample is made, however, appears only the first column for each sample, I would…
-
1
votes1
answer599
viewsHow to recover PHP array for javascript comparison?
I have a code in javascript that sends some elements of the page to another in PHP via ajax and there are made some comparisons. Then it returns me this array with the function print_r() : However,…
-
1
votes1
answer928
viewsIn descending order, remove a value from the inserted number to 0
I need the program to remove a value from the user’s number until it reaches 0. I don’t know if the loop used should be the for, but my program was like this. package numerodescrecente; import…
-
1
votes1
answer38
viewsI can’t run the jquerry loop
I need to create a loop so I can feed it a graphic. while($(".previsto").eq(0).text(),){} I need to take these values eq(0), eq(1), eq(2)... $(".previsto").eq(0).text(), $(".previsto").eq(1).text(),…
-
1
votes1
answer34
viewsMake cumulative value in loop
var previsto = []; for(var i = 0; i < $(".previsto").length ; i++) { previsto[i] = $(".previsto").eq(i).text(); } I need to take the next amount adding up the previous one, to have a buildup.…
-
1
votes3
answers97
viewsExecution or not of the increment in loops for
Code 1: var x = 1; for( ; x<6 ; x+=2 ){ x=x*x; } console.log(x); In the above code even if the condition is false the incrementing part is last executed. Code 2: var x = 0; for( ; x<8 ; x++…
-
1
votes3
answers286
viewsTo create alphabetical list in PHP according to variable number
I need to create a list of letters in alphabetical order, according to the variable $nalternatives, for example: $alternativas = 3; aí preciso criar: a b c If $nalternatives is 2, then it’s just a,…
-
1
votes2
answers73
viewsHow to Filter an array using the For structure?
how I can filter an array using the structure for ? The code is this: const numeros = [1,2,3,4,5,55,190,355,747,1000,125]; I need to filter the numbers under 10. I used it this way, but I was asked…
-
1
votes2
answers78
viewsLoop step size for MATLAB
I have the following loop in MATLAB, I would like to know how I can increase my k variable from 0.15 to 0.15 until 10. for k=1:1:10 %... end
-
1
votes1
answer82
viewsCan someone please explain some of that code to me?
The code in question is the bottom one, a lot of it I’m understanding more the loop for confused me, it gets the sequence of the variable, but in print, it informs exactly the sequence that the user…
-
1
votes1
answer502
viewsHow to return the last element of the array using the for method?
I wanted to know how I got the last element of array using the structure for in the case of decreasing? This is my code: const a = n => n % 2 === 0; function callbackfn (valorInserido, funcao) {…
-
1
votes0
answers423
viewsLoop, For, PL/SQL cursors (Doubt)
Good morning Guys, my doubt is the following, my table is so currently: Nome Idade ID João 5 Lucas 5 João 2 Lucas 1 I wish she’d stay that way: Nome Idade ID João 2 1 João 5 2 Lucas 1 1 Lucas 5 2…
-
1
votes2
answers592
viewsHow does Length work outside and inside For in Javascript?
I have a constant doubt about the Length and the noose for to measure an array or a string. Doubt 1: When we use that code: const numero ="teste"; const medir = numero.length; console.log(medir) It…
-
1
votes2
answers923
viewsInside For (Explanation)
I returned to study logic, because I was studying only front-end and hit me a very rough doubt, about one was of another. for (var i = 1; i <=10 ; i++) { for (var i2 = 1; i2 <=10; i2++){…
-
1
votes1
answer377
viewsFOR syntax in C
I’m new to the community, and I recently noticed in a C code, a FOR loop, with the following syntax. for(;;). Someone could explain that syntax to me. Thanks in advance.
-
1
votes3
answers444
viewsFactorial from 0 to 20 using For
I need to do the following exercise: "Using the for loop, calculate and print the factorial of all numbers between 0 and 20. Use Double type. Ex: 0! =1 1! =1 2! = 2 ... 20! = 2432902008176640000"…
-
1
votes4
answers365
viewsRepetition for calling variables
I have four variables [t1, t2, T3, T4], and each of them was defined as a string previously. t1 = 'A vida vai ficando cada vez mais dura perto do topo.' t2 = 'A moralidade é a melhor de todas as…
-
1
votes0
answers67
viewsPHP - Split list and print
I’m creating a script for study and I need to split the list into array. So you can be informed in for or foreach. That in each tested account is informed the result on the screen and so on... I’m…
-
1
votes2
answers131
viewsLoop logic with for
Consider the Javascript code below. var r = [2, 5, 6, 18, 20, 10, 23, 12, 19, 10]; var s = [1, 5, 7, 13, 18, 21, 10, 25, 32, 17, 3]; var x = [0]; var i; for (i = 0; i <= 9; i++) { x[i] = r[i]; }…
-
1
votes2
answers783
viewsHow to implement the cosine function using Taylor series in Python?
Guys, I have the following problem: Until then I made the following code: import math def cos(x, n): soma = 1 formula = (((-1)**n)*(x**2*n))/math.factorial(2*n) for i in range(n): soma += formula…
-
1
votes0
answers137
viewsVault Secret Issue - OBI 2017
I’m solving the following OBI problem: https://olimpiada.ic.unicamp.br/pratique/p1/2017/f1/cofre/ Vault Secret The secret system to open this vault is quite complex. Instead of rotating a button…
-
1
votes2
answers78
viewsHow to display and hide Toogle inside ngfor correctly?
listNotas() { this.service.getList(this.idAluno).subscribe( data => { this.error = data.error; this.list = data.message; console.log(this.list); }, err => console.log(err) ); }…
-
1
votes1
answer799
viewsC / How to exchange for a while?
Write the function prints using the while repeat structure instead of for. If necessary I can edit and insert all the code. void imprime(Ccc *p) { Ccc *r; for (r = p; r!=NULL; r = r->proximo)…
-
1
votes2
answers78
viewsIs going into loop
I’m taking the values of the array and trying to pass the for, but it eventually getting into loop and bringing the values 1,2,3,4,5,6.... array_push($var, $linha['data']); array_push($var,…
-
1
votes1
answer75
viewsVariable loses value inside "for"
a=2 for a in range (9) : print (a+1) Why using the for, in this case, it is printed from 1 to 9, and the variable a is equal to 2?
-
1
votes2
answers48
views -
1
votes1
answer1396
viewsSort list with Python + Django
Good afternoon guys, I have a problem, register by the Django admin a video that should be sent to my template, however I need these videos to be ordered by the field position that I have in my…
-
1
votes1
answer82
viewsI am trying to print an array using for in javascript, but it is not displayed correctly
I printed it manually and then tried using a for to carry out the printing, but I happen not to be able to display it properly. let mochila = new Array(); let item1 = ['corda', 2], item2 = ['faca',…
-
1
votes2
answers80
viewsHow do I use the for command to solve the same problem?
In this case, the objective of the program was to make a half pyramid, as many floors as the user wanted to build, however, he wanted to use the 'for' command to accomplish this goal. quant =…
-
1
votes1
answer98
viewsIterate values of two requests in *ngFor
I am making two requests in the bank, one brings the orders grouped only for view on the front, the other brings all values, the last need to show the total of each request along with the view of…
-
1
votes1
answer37
viewsCreate loop and move to arguments of a function?
I have the following code in Python: storage.tableWidget.setColumnWidth(0, 30) storage.tableWidget.setColumnWidth(1, 140) storage.tableWidget.setColumnWidth(2, 90)…
-
1
votes1
answer103
viewsCreate menu inside an Alert() with repeat loop
I am trying to create a menu of options for the user to choose one of the 20 previous exercises to open in the browser. Only instead of creating it manually, I use the repeating structure for with…
-
1
votes1
answer69
viewsJquery - Add element to each certain amount of other elements
I need to add a tag breaking (<br> or <hr>) each quantity of <div> dynamically arising. For PHP, i group 10 records by <div>, that is, every 10 records creates a <div>…
-
1
votes1
answer159
viewsManipulating divisible 3 and 5
I have a statement that says I have to make a looping between 4 and 24, adding the index with a total value, with some points: If the index number is multiple of 5, it must add up to 3; If the index…
-
1
votes1
answer652
viewsPython - Tabuada- For Exercise - Matrix
Good night! I’m trying to create a tabuada program using for and matrix, my code is like this at the moment: def crie_array(rows, columns, value): matriz = [] for i in range(linhas): linha = [] for…
-
1
votes2
answers47
viewsMysql Query with Infinite Loop in C#
I’m doing a project with creating dynamic objects with CSS, after he enters the for, he inserts all the data of the database right, but apparently at the end he makes an infinite loop and appears…
-
1
votes1
answer51
viewsPython Dataframe dynamically
I have data with the following columns: "Date","Codproduct","Sale","Quantity" I need to create several data frames in python, filtering product and selecting the other columns and always saved with…
-
1
votes1
answer40
viewsHow do I do a repeat structure function on R?
I’m trying this way: H <- function(n) { for (i in 1:length(n)) { x <- 0 a <- 2 b <- 3 func = x + a/b a+2 b+2 return(func) } } Does anyone know how to solve?…
-
1
votes1
answer55
viewsDifference of the same code with and without for()
I am mounting a jQuery code with dateTimePicker Bootstrap. I’m tried a problem which is this: when I do it in a more extensive way it works perfectly, but when I try to do it in a more simplified,…
-
1
votes0
answers39
viewsProblem with repeated data in PHP table
I have a doubt, when making a select to fill a field if it is equal to real it should fill ex: the item 1 in the value of 1 real the item 2 in the value of 2 and the item in the value of 3, however…
-
1
votes1
answer137
viewsDoubt about closures, function inside loop
I’m studying about closures in Javascript based on the book "You Don’t Know Js" by Kyle Simpson. I understood the concept of closure, that he can "hold" the reference to the lexical scope outside…
-
1
votes2
answers562
viewsHow to go through two lists of different sizes [PYTHON]?
The idea is as follows: Each team has 6 maps played (mapList) I made a web Rawler that takes all the information related to the team and the map and wanted to insert automatically in a spreadsheet…
-
1
votes1
answer54
viewsHow to extract strings from 4 different files, and insert into a single line of an HTML document
For hours I’ve been trying to find a way to include the contents of 4 distinct files for a new output file -; "output.html". The 4 files I’m looking to extract information from are: link.txt…
-
1
votes1
answer54
viewsAt the last run of the repeat loop the entered value is assigned to my counter
I put a printf() to track what happened and everything was normal, until I type my last value and it is assigned to the counter quantN. The conditional even works when it is a negative value, it…
-
1
votes1
answer66
viewsFind equal names(string) in two distinct dataframes and add a column in the second data frame with another data from the first
Hello. I have two data frames: Times with 629 lines. rank prev_rank name league off def spi 0 1 1 Manchester City Barclays Premier League 3.34 0.24 95.24 1 2 2 Liverpool Barclays Premier League 2.95…
-
1
votes1
answer82
viewsPascal’s triangle is in infinity
I’m making a code that generates a Pascal triangle for a project of mine, but when I spin it gets stuck, as if the is infinite. function pascal(n) { var d; var uau = ""; var line; var i; for(line =…
-
1
votes1
answer108
viewsFor nested only works in first iteration (Python)
I’m trying to get one nested to compare lines in two different csv files, but after the first interaction of the first file is searched inside the second file and skip to the second iteration, the…
-
1
votes1
answer141
viewsList table array horizontally and vertically
I’m trying to list the company name horizontally, the quantities of the products just below each company name, and the product name in the first column vertically. My code is this, but not this…