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
answers42
viewsLoop is not walking, does not leave the first position
f3 <- function(n) { dados <- rnorm(n, mean = 0, sd = 1) matrizB <- matrix(0,2, n) for (i in 1:length(dados)) { s <- 1 if (i <= 0.2) { matrizB[1,] <- 1 matrizB[2,] <- 0.2 } if (i…
-
-1
votes1
answer23
views -
-2
votes1
answer1122
views"String index out of range: 5"
There is an error mentioned in the question in my java program. The program is a barcode reader. The user informs the digits of the code (except the last one). The sum of the numbers q are in odd…
-
-2
votes1
answer101
viewsProblem with array loop - Javascript
When I try to run the loop, even if I want to enter the is, I already checked and the array with the object is not empty, but does not execute the loop... Any idea? var caminho = [];…
-
-2
votes2
answers1446
viewsHow to pick up array index?
I have the following APEX code List<integer> entrada = new List<integer>(); public static void generateStringArray(integer entrada){ List<String> ListaPrincipal = new…
-
-2
votes1
answer103
viewsHow to add values from a for structure?
So, I need to solve a little problem in my code (I’m very newb), I’m just programming because I need it for my TCC, I don’t know much python but I’m trying to turn around. On line 126 there’s that…
-
-2
votes1
answer712
viewsFunction passing
Run a function called passWhy you print on the console "here I have the value of x" where x will be the value of i in each iteration, for each value from 0 to 3. Only it gives this error message:…
-
-2
votes2
answers110
viewsUsing the for command in Javascript
People, can you help me ? I am trying to get a function to be executed and to return the word "Blue" 4 times, through a Cycle. I tried to write this here, but it gave the following error…
-
-2
votes1
answer34
viewsRemoving higher value from line with for
Good afternoon, I’m trying to extract the largest whole value from every line of my dataframe. I created the following code for this: for i in df.index: df["maxx"] = df.loc[i].max() df["minn"] =…
-
-2
votes1
answer811
viewsHow to make loops in R
I’m working on climate data and I need to do a boundary analysis for every element of my database. I need to make loops because my database is too big, but I don’t know where to start. One part of…
-
-2
votes1
answer186
viewsStatement for 2 arguments, how does it work?
I saw this statement in a code on codewars and I couldn’t understand how it works: def multiple_of_index(arr): return [val for index, val in enumerate(arr) if index and val % index == 0]…
-
-2
votes2
answers204
viewsIs there any way to nest one for N times?
In Python is there any way to nest one for inside the other N times? Or is there some kind of algorithm that simulates this? Basically I need to create a function, which performs combinations of…
-
-2
votes1
answer46
viewsIs it possible to create dictionaries using surreptitious ties?
I was wondering if I could create a dictionary using loops. But I don’t want to create a dictionary within a list [{ }]. example: from random import randint jog = dict() for n in range(1, 5):…
-
-2
votes1
answer39
viewsCalculate the product within a for loop
I need to calculate the product of 3 numbers inside a loop for, but the code I made is going wrong, multiplying something bizarre that I couldn’t even understand, for example, if I input 1, 1, 1, it…
-
-2
votes1
answer31
viewsStop Loop For when a certain number is typed
I’m trying to stop a loop for when the number 42 is typed. Even my code is like this: var numero = prompt('Digite o numero') var arrNumero = [] arrNumero.push(numero) console.log(arrNumero) for (let…
-
-2
votes2
answers84
viewsHow do I create a time interval in the execution of a for?
How I create a 1 second interval in the execution of the for or of function? JavaScript: function Linha1() { for (var i1 = 0; i1 <= 3; i1++, Linha1.setInterval(1000)) { if (notas1[0][i1] == 1) {…
-
-2
votes1
answer59
viewsCan you improve my code?
Hi, I’m Vitor, and I’m new to programming and Stack Overflow, and I’d like some tips on how to clean my code. ->Code to read 50 integers between 0 and 9 and count how many times each number was…
-
-2
votes1
answer88
viewsProblem checking for an array
I was doing a very simple old game, and the same done, I wanted to leave the automatic win check, because it was very "hard-code". The way I found to do this was by running a for, and whenever it…
-
-2
votes1
answer54
views -
-2
votes1
answer25
viewsdisplay array result within phpmailer message
Good evening folks, I need to display the results of an array in a message body phpmailer, so send the same by email. My sending code is working and I have done several tests, the email arrives…
-
-2
votes1
answer32
viewsArray javascript - know number of agencies I have
I needed to know how many agencies I have in my json file and their respective numbers, in case I know they are 4, but the return being given is an array of 120 accounts only, and I would like an…
-
-2
votes2
answers70
viewsPython - Checking items in a list
I have a scenario, a little confused to explain... but I’ll try... I need to compare listA with listaB, where case 1 or more items from listaA are within the listaB, I print it on the screen, but in…
-
-2
votes1
answer19
viewsHow to Browse a List With Map and Array List Within the Same List (JAVA)Springboot
I need to go through this List (List) however I cannot, I need to pass the value "options",take the value "option_Id", and go through the option_value and bring the option_value_id and Name in…
-
-3
votes2
answers82
views -
-3
votes1
answer286
viewsHow to increment and decrease using FOR?
I’m not getting to increment the variable with each click on one button. Example: a Button and a Paragraph, every click on button, increase the value in Paragraph, example, from 0 to 1, and each…
-
-3
votes1
answer121
viewsREPEAT NUMBERS EVERY 4 TIMES IN PHP
Hello, sorry for the ignorance is that I am now entering the back-end and I need a 'for' that repeats the same number of 4 in 4, at each repetition it increments, receives one more FOR EXAMPLE: MUST…
-
-3
votes2
answers85
viewsI am learning Python and have an exercise using the FOR that I am not able to do, can anyone help me?
Build an algorithm that reads the age and sex of 5 people, providing: *The number of men and women; *The average age of men and women; *The greatest age among men; *The lowest age among women. This…
-
-3
votes2
answers126
viewsHow to operate on the counter of a while in each loop iteration
Sorry my ignorance I’m starting to learn python now, my doubt is: How can I generate a result in each iteration of a while. valor= input('digite o numero desejado:') contador = 0 while contador…
-
-3
votes1
answer68
viewsWhy does my function only return "even"?
function parimp(n){ for(var i = 0; i <= n; i++){ if(i % 2 == 0){ return "par"; }else{ return "impar"; } } } var s =…
-
-3
votes2
answers64
viewsBug when adding elements to the list and transforming it into a string
I’m trying to headache in the course of a mini-project to develop a hangman game, in the function that would return the string containing the hidden word, showing only the guessed letters. I’ve…
-
-3
votes1
answer31
viewsHow to always take the next 2 elements of a string
I have the following string: gxAjaxKey = "FF00FFFFFFFF2426FFFFFF046448FF70" I must take 2 elements at a time from this string and convert to byte: FF = 255 00 = 0 FF = 255 . . . 70 = 112 I wrote the…
-
-3
votes1
answer40
viewsHow do I put a close button on my python file?
I’m starting in python and I’m writing a code, but when all the actions end the program closes, how do I put a command where for example click ESC and it closes? I want that when the person does not…
-
-3
votes1
answer26
viewsHow to consist of a data frame against a valid value array?
I have an array of all possible values that appear in a set of columns of a data frame. The number of components in the vector is different from the number of observations of the data frame. My goal…
-
-3
votes1
answer107
viewsC number of approved students failed
Please, I need the total amount of failed and substitute students approved program Elaborate program C to calculate and display the average of 3 students in a given discipline. The simple arithmetic…
-
-3
votes1
answer62
viewsProblem with switch case inside for loop
I need help with my code with switch case inside for loop. I’m a beginner in programming and I don’t understand why the loop doesn’t run as desired. The desired would be to run the printfs before…
-
-3
votes2
answers63
viewsInfinity C loop array
In this example below, how do I print on the screen all values assigned to n during the loop, after its completion? #include <stdio.h> #include <conio.h> int main (void) { int n; for…
-
-4
votes2
answers3074
viewsHow to calculate numbers in a given range?
How could I compute the sum of the numbers in a range of 1 to 500 in which the summed numbers of that range should be odd and multiple of three? I only managed to take the break so far: for c in…
-
-4
votes2
answers259
viewsGet the position in a for loop in java?
My java code: for (Construtor usuario: users){ Construtor USER = new Construtor(user.getNomeUsuario); arrayList.add(USER); } ** How do I get the position of the loop in this configuration above? See…
-
-4
votes1
answer136
viewsGo inside another For
Guys I’m needing to run a for inside another for but I’m not getting it. I need to store the result value within a variable. I’m not familiar with python, I believe this is the biggest problem.…
-
-4
votes1
answer178
viewsWith creating a program that reads 10 numbers and writes the lowest and highest read value (Python)?
I’m having a little trouble with this exercise. Here is my code: python num = float(input('Digite o 1 numero: ')) guarda_maior = num guarda_menor = num for n in range(1, 10): num =…
-
-4
votes2
answers49
views(python) as I put the go inside def
numero_sorte = 3 n_tentativas = 4 for rodada in range(1,n_tentativas): tentativa_2 = input ('qual o numero secreto? ') tentativa_2= int (tentativa_2) def jogo_adivinha(chute): if numero_sorte ==…
-
-4
votes1
answer35
viewsHow do I make a series of numbers (3-in-3). Using for x in range?
How I make a series of numbers (3-in-3). Using for x in range ?
-
-4
votes2
answers68
viewsJavascript function using For
I have an array with the height of several students and need to sort in groups by height. I do a for to scan the array and inside the for a conditional if to know if the student enters that group,…
-
-4
votes1
answer69
viewsIs there a way back to a particular line of code?
I would like to know if there is any module, function, etc. that would allow me to go back to a certain line of code. I have this doubt because, whenever I want to ask a question repeatedly, I have…
-
-4
votes1
answer32
viewsCreate a program that reads a number between 2 and 20 and generate a screen with the configuration shown below:
the program must display the following result: Type a random number between 2 and 20: 7 Exit from the program: 1234567 x123456 xx12345 xxx1235 xxxx123 xxxxx12 xxxxxx1 (NOTE: the value typed by the…
-
-5
votes2
answers80
viewsHow do I check which items in List2 are in List1, then their count and order
I am a beginner in Python and I would like to count on your help for the problems below. I have worked on two lists as the following objectives: 1.Check which items in List2 are in List1 2.Count…