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
-
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
votes2
answers178
viewsHow to create events in a for repeat structure?
My question is the following, I am developing a program (I am beginner) in C#. The part I wanted to improve on is the following: I’m wanting to create different events in a for structure. For…
-
2
votes2
answers186
viewsRemove item from a collection
Why is it considered incorrect to remove an object from a collection in this way? And why the exception launch ConcurrentModificationException? for(String item: list) { list.remove(item); }…
-
2
votes1
answer244
viewsHow to increment a div using For Javascript
I’m with this code but it’s not picking up. I want to increment every click on "Increment". Code: function incrementar(){ for (let i =0; i<10; i++){…
-
2
votes2
answers116
viewsHow to return a specific column as an element with FOR XML AUTO clause
I need to make a certain column an element in the return xml when I use the FOR XML AUTO clause. Auto-return transforms all fields into attributes of the corresponding element. All right, but either…
-
2
votes2
answers172
viewsInitialize variable in a "for"
I remember that in C language I didn’t need to initialize the variable (in case i) with a value, I tried to do the same on C# and got a build error. In C# I am required to set the value of the…
-
2
votes2
answers107
viewsUsing for loop in a list with charts in R
This is my code: library(ggplot2) library(gridExtra) df <- data.frame(x = 1:100, y1 = runif(100), y2 = runif(100)^2) plot_list <- list( plot1 = ggplot(df, aes(x, y1)) + geom_point(), plot2 =…
-
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
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…
-
2
votes3
answers502
viewsPython - Cycle for as an alternative to the while cycle
General considerations: I am currently programming in python; I have a relatively simple level code; The code contains an instruction cycle of the type while loop; I would like to know if there is a…
-
2
votes1
answer154
viewsFor do not wait to finish requisition, it continues counting
I am developing an application in Ionic and I have a problem when I do a loop loop. In this loop there is a call from a method of a previous, that makes a request put. My problem is that the for…
-
2
votes1
answer48
viewsHow to take the value of multiple items and change according to my if
I have a list of items (that comes from the database), I need to compare each item of one of these and if the value is 0 change the text. Below is the function I’m trying to use to change the value…
-
2
votes0
answers128
views -
2
votes2
answers52
viewsHow does a forloop generate random values, then "appenda" the next set of generated values?
k <- 8 m = 100 for (i in 1:k){ x <- rnorm(mean = i, sd = .5, n=m) y <- rnorm(mean = (8-i), sd = .5, n=m) amostra2 <- data.frame(x,y) } This is the code I have. Given k and m, I give…
-
2
votes3
answers1958
viewsHow to print list elements in reverse order?
I created a program that takes integers from the user and prints them back in the reverse order that received them, however my program is not returning all integers it receives. When I enter 9…
-
2
votes1
answer49
viewsDoubt with print and with for
for l in arquivo: Print(l) In this file are the name information, IP and Hostname. I need to print the name, IP and Hostname, however in this format: Name space of 10 characters Ip space of 10…
-
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
answer464
viewsI need help showing all the items in an array with Javascript
I am using AXIOS to access the API and can return only the first result. I copied only one part of the code below, but everything works perfectly when I enter the index [0].…
-
2
votes0
answers539
viewsWhat is the difference between the infinite loops for(;;) and while(true)?
What is the difference between infinite loops for(;;) and while(true)? Is there any advantage or disadvantage of using one or the other? For example, in a simple terminal input validation code, to…
-
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
votes1
answer69
viewsHow do I use the semicolon in the "for" command?
What’s the difference between a for ending with a semicolon and a for ending without a semicolon? Example: for(i=0; i<=10; i++)**;** //Termina com ponto e vírgula// Example: for(i=0; i<=10;…
-
2
votes1
answer68
viewsHow to use Try with while and vectors
I need to create a code where the user enters 4 whole numbers and if anything else is typed an exception treatment. I’m having problems with the catch, I’m not able to do that when the exception…
-
2
votes2
answers92
viewsDoes pushing inside a for loop not increment a declared Let in its scope?
I was reading the series You Don’t Know JS which says the following about let declared in for loops: There’s a special behavior defined for let declarations used in the head of a for-loop. This…
-
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…
-
1
votes1
answer64
viewsRead a vector to a stop bit
I want to read an 8-bit binary vector backwards and stop until I read the last 1. For example: [00010101] <--- Read until you find the last 1 Vector read: [1010] Then associate a function for…
-
1
votes0
answers97
viewsPHP/Bootstrap - Replay up to X and then up to Y then includes new DIV and continues replay
I’m breaking my head in this repetition, as this is my first question, sorry for the mistakes. :) Currently I have this block of codes inside the container: <?php echo '<div class="row">';…
-
1
votes2
answers215
viewsInsert a dot in the penultimate variable item
I have a variable with the value "14013" and I’m trying to insert a point to have the following value "140.13" in my loop. for (var i in teste) { for (var j in (teste2[teste[i]])) { valorFinal[j] =…
-
1
votes1
answer311
viewsVariable not defined in Python for-loop
I have a problem in a code that should read 4 values using raw.input().split() and then a for-loop to turn such values into float. The interpreter returns to me: "name 'val' is not defined" Follows…
-
1
votes3
answers399
viewsDoubt about C pointers
void imprime (char *v, int n) { char *c; for (c = v; c < v + n; v++) printf ("%c", *c); } I have this function, but I don’t understand what exactly she’s doing and how the pointers behave in this…
-
1
votes1
answer140
viewsFor nested in parallel
I’m trying to spin two for nested. The second would like it to be parallel. It follows my code. for (int i = 0; i < original.Width; i++) { Parallel.For(0, original.Height, j => { Color…
-
1
votes2
answers76
viewsError while running script
#include<stdio.h> #include<math.h> int main ( void ){ int x; int i; printf("Input the number (Table to be calculated) : "); scanf("%d", x); for( i = 1; i <= 10; i++){ printf("%d x %d…
-
1
votes2
answers12804
viewsCounter in python
Well I’m doing a screenshot program but I want it to replace in the file name when saving, the characters "XX" by the print number. Ex: Screenshotxx.jpg in "XX" I want to put the print number ex:…
-
1
votes1
answer1233
viewsAdd days on increasing date via For
In the code below I add 1 to each step in the variable i, to add 30 days in the field dt, I need another for or you can do it yourself? DbConnection cnx = ADO_Utils.GetConnection(); DbCommand cmd =…
-
1
votes1
answer647
viewsCan someone explain to me what is a Gothic Moon tie?
I already know the bonds while,repeat and for,but when I was seeing the types of loops, for generic" . The text was in English.
-
1
votes1
answer139
viewsfor em onload Javascript
Why I don’t get to call the function showSeatStatus(i);? window.onload = function() { //Conecta os eventos de imagem de poltrona for (var i = 0; i < tamanhoMatriz; i++) {…
-
1
votes2
answers91
viewsErasing bottom lines up
I’m using the method innerHTML(); to display 60 lines on the page. As soon as, I need to delete 20 to 20 lines à every click on the button. Complete source code: for (i = 0; i <= 60; i += 1) {…
-
1
votes2
answers1443
viewsHow to make a nested FOR?
I’m opening two files, one is a text, and the other is a list. I want through nested check how many times each item in the list appears in the text. I did so: arquivo = open('texto.txt', 'r') lista…
-
1
votes1
answer241
viewsHow to insert data using query in a for loop?
I’m trying to insert data into the mysql DB being that some data repeats and others not so who would command the number of executions would be the for, but it is not running the query inside for. I…
-
1
votes1
answer498
viewsPrime number algorithm only works for the first verified number
I created a program to check primes and in it I receive n entries. That is to say, n is the number of test cases. The problem is that in the first test case everything works fine. Already in the…
-
1
votes2
answers82
viewsMy while closes before what really should
I made a code that should take the number of rows of a txt file and then use this same number of rows in a while to convert columns and rows into array. lines = 0 ln = 0 for line in dataset: line =…
-
1
votes1
answer100
viewsNested for conversion to threads
I got the following for nested throughout the length of an image bitmap in C#. I would like to rotate the second one with threads to be executed in parallel. Bitmap alterado = new…
-
1
votes1
answer78
viewsList append on for loop - Swift 3 / Xcode 8
I’m having a problem Adding items to a list Inside the 'for' loop, Where all items in the list are repeated with the last value entered. Here is my Nsmanagedobject list var listCursosNovos: [Cursos]…
-
1
votes2
answers75
viewsSyntax error no for?
Error: (only assignment call increment decrement and new Object Expressions can be used as a statement) I do not understand why you are giving this error, being that the variable is of type int...…
-
1
votes1
answer185
viewsLogical doubt of PHP code
Hello, folks. I’m starting in PHP and am having some problems with this code: <?php function linha($semana) { echo "<tr>"; for ($i= 0; $i <= 6; $i++) { if (isset($semana[$i])) { echo…
-
1
votes2
answers173
viewsWhat is the logic of python for i 'in'
I’d like to know the logic of for i in vogais, as in the example. Doubt, it carries the entire typed word in a list in memory and already sorts according to our classification,or it reads character…
-
1
votes1
answer3593
viewsHow to compare a string of an array in C?
I have the following variables : char nome[10][8]; int i; --> Sendo esta para o loop I ask the user to enter 5 names and then I read the variable : printf("Entre 5 nomes : \n"); for(i=0; i< 5…
-
1
votes1
answer121
viewsRecreate HTML elements from one Div to another Div by Classname
Well, some will suggest me using the cloneNode(true) Javascript to make a appendChild(var) in the GIFT. But for this case, I have used this native resource, but it did not meet my need. Why, when I…
-
1
votes1
answer22
viewsresult.lenght ajax error with wcf
The following script works in part: <script type="text/javascript"> function ConsUsuario(){ var value = $("#codUser").val(); $.ajax({ type: "GET", url:…
-
1
votes1
answer100
views