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
votes1
answer131
viewsHow to Stop an Infinite Loop For - Vue
I’m doing a project with Vuejs and I have these two functions running through an array provided by a JSON fetch. import { api, getCep } from "@/services.js"; export default { name: 'Casos', data() {…
-
1
votes2
answers884
viewsPython - how to create a two-dimensional matrix with for loops
Hello The code below gives the following error message: Traceback (Most recent call last): File "C:/Users/Usuario/Documents/tests python/várias.py", line 12, in mult[i][j] = (i*j) Indexerror: list…
-
1
votes2
answers237
views -
1
votes2
answers116
viewsHow to create a factorial function using the 'for' counter?
Let’s get to the point: I would like to create a factorial function using the counter for calculating the factor of the parameter numero. Remembering that 0! = 1 and 1! = 1. My code is like this:…
-
1
votes1
answer259
viewsMake a Map and take the values
I have a Map and within it I have another Map and I need to make a for and take the values that are in those maps, how it can be done? The structure and shape that the Map is created like this:…
-
1
votes1
answer105
viewsFor in the C language
I studied the iterative artifice for and thought the same applied to the following example: for(i = 0; i < 7; i++){Código} However, when studying the pointer part with vectors, I came across the…
-
1
votes2
answers170
viewsHow to place two arrays inside a single loop of repetition to populate an object?
Based in that and in that reply, I am creating an instant search box that returns results based on the items of two arrays with elements p and a of certain classes present on the page. The idea is…
-
1
votes1
answer195
viewsCheck if the content already exists in the text file
I would like to know how to check a TXT file and if you have a line like it does not add the content again, otherwise it adds. I tried to do so: Tokens is an array with several strings, for example:…
-
1
votes2
answers62
viewsRepeat loop in C++
Good night, my friends! I’m starting the ADS course and I have a question. I need to create a loop of repetition for 50 students by collecting 4 grades of 4 exams, and at the end, present a report…
-
1
votes1
answer49
viewshow do I use the for correctly?
I’m doing an EP activity and he asked me for it in the image, but I got stuck in the sequence part, because, like the sequence is the top numbers is a sequence growing from 1 to infinity, and…
-
1
votes1
answer56
viewsHow to reduce the size of this function that contains multiple if?
I wanted to think of a logic that would decrease the size of this code, because it ends up repeating itself. It is an experience calculator for a game. You set your current level and the level you…
-
1
votes3
answers59
viewsValue of a "for" returned infinitely
Contextualizing: I have an exercise that suggests creating a program to read student grades and show grades equal or higher than average. Thus, the following code was written: #include…
-
1
votes1
answer106
viewsDoubt about looping loops in C
I’m trying to solve this question: 3. The user enters two numbers x and y (with x < y): (b) The program returns the sum of the perfect numbers of the range [x, y]. However, he returns the number…
-
0
votes1
answer261
viewsHow to run multiple FOR at the same time
In the code below I have 4 for and they run in sequence, but I need them to run them all at the same time. public class main { public static void main(String[] args) { long init =…
-
0
votes1
answer325
viewsCount number of occurrences in a for in loop {Bash}
I have the following script #!/bin/bash for file in *.jpg; do convert $file -resize 1920x1080! -blur 0x8 alterado$file; echo "A Processar o ficheiro $file" done I want to do an echo with Processor…
-
0
votes2
answers91
views -
0
votes0
answers40
views"change-making" algorithm - Smallest amount of currencies possible
Given the Change-Making algorithm: change(C1, C2, ...., Cr: valores de denominações de moedas, onde C1 > C2 > ... > Cr; n: inteiro positivo) for i := 1 para r di := 0 {di conta a…
-
0
votes2
answers105
viewsFor rule in C
I have a doubt about the cycle being , that is, I have an instruction for and I have to get the result that the machine gave. have this : for(x=2,Y=1;X < 11;x++)y+=x++ I know the X variable…
-
0
votes1
answer2606
viewsInsert a loop inside another loop
I wish to add the second to the first. For illustration, I will use the simple example below as a basis: <script> n = 10; for ( var i = 0; i < n; i++){document.body.innerHTML += i;} for (…
-
0
votes0
answers611
viewsRetrieve FOR loop variable inside a FOREACH - php
Hi, I have two loops in the structure of my code. The first is a FOR that mounts an array with data. And I have a foreach that runs through a BD data. I want to use the variable that returns in FOR…
-
0
votes1
answer577
viewsJava - Swing - Timeunit.Leep time counter
I’m using Swing in Netbeans, creating a simple math game (thought more feasible than a calculator) whose goal is to add up the random numbers of the buttons until it equals a number between 1 and…
-
0
votes1
answer1432
viewsHow to transform a while structure into for? And vice versa?
I am in need of an explanation on how to turn a structure into while to for and vice versa. I thank anyone who can help!
-
0
votes2
answers1311
viewsHow do list sorted by letter?
I suppose I have a list of names, at array in Javascript. But I’m looking for a way to do it in the suggestion box style, where you only press an alphabetical key inside the field and as soon as you…
-
0
votes1
answer96
viewsJavascript + PHP
Hi, I need your help; I have my While in PHP, listing all the materials, their quantities and a space where the Total is calculated as the quantity of the product increases. Here my PHP: <?php…
-
0
votes1
answer50
viewsIgnore JSON element with PHP
Let’s say we have a JSON with 2 elements to follow: exemplo: { [{ "arquivo": "Arquio 1", "size": "2340" }, { "arquivo": "Arquivo 2", "size": "0" }, { "arquivo": "arquivo 3", "size": "4329" } Use PHP…
-
0
votes1
answer767
viewsProblem with FOR loop interaction using Tstringlist
I have a TStringList which stores absolute path names of some files and I want to put these names in a text file only if the current verified name does not yet exist within text file. When…
-
0
votes2
answers5055
viewsLargest/Minor/Sum in C++ using for
I want to make a program that reads 5 numbers and tells me the largest number, the smallest number and the sum of the numbers, in C++ using the loop for. I’ve tried and done so: #include…
-
0
votes1
answer159
viewsWhat is the explanation for the following question
This is a matter of the simulated java certification of the Whizlabs site. public class Whizlabs { public static void main(String[] args) { int[] testData = {1, 2, 3}; for(abc){ } } } The question…
-
0
votes0
answers178
viewsIndex of Vector in C
I have this function which is called through a menu of options: char cad_cliente()//cadastro de clientes { char resp;//variavel de resposta se cpf invalido system("cls");//limpa tela for(int c = 0;…
-
0
votes1
answer115
viewsMake a subset with the same condition on different bases in R
I’m willing to apply the same condition subset on different bases in the R. I thought the for was going to solve, but I did not succeed. Follows programming used: for(i in c("mar16", "jun16",…
-
0
votes1
answer35
viewsDoubt about vector
I am trying to list the numbers that the user type but am not finding the function,someone can give me a light? class Program { static void Main(string[] args) { int[] atividade = new int[6]; for…
-
0
votes1
answer372
viewsFor loop in Java
need to receive an n number and then repeat the receipt and processing of the v string, n times. I tried to do the following: import java.util.Scanner; public class Main { public static void…
-
0
votes2
answers922
views -
0
votes1
answer59
viewsCounters are not being incremented in code
I am facing some difficulties with the code snippet below: The call of this function is: cache = OperaCache(true , endereco, op, cache, descricao, read_hits, read_misses, write_hits, write_misses);…
-
0
votes1
answer569
viewsHow to replace the contents of an array?
I have a div (users' mosaic) that within it has a array (javascript) with photos of users(data coming from the database). The amount of photos of users must be less than or equal to 15. If the array…
-
0
votes0
answers110
viewsVector in Opengl
Hello, I’m venturing into Opengl and so far I know the basics of creating figures. I need to create a bar number that goes from 1 to 64, the problem is I need to do this with a FOR. When the first…
-
0
votes2
answers112
viewsHow to use "for" and "While" to capture cell tags from various tables in an html file?
I have several HTML files that I need to capture the data inside the tables, to launch in the database, but I’m not able to navigate in the html tree to find the tags that are cells, the html is…
-
0
votes0
answers35
viewsOutofbounds Error
Good, I would ask you to help me with this mistake! This is part of a game code, the idea and print something like this M M M 123456789012345678901 1 2 M positions will vary with each move, Thank…
-
0
votes1
answer135
viewsWord in reverse order
I’m doing an exercise where I have to make the word given with input exit in reverse order. I start by counting the number of letters you have in the typed word (commented on in the code). After…
-
0
votes1
answer1247
viewsHow to make an asterisk triangle in java
I want to get the following output: n:4 + ++ +++ ++++ That is, I insert an "n" and I will get a kind of triangle in which the base corresponds to a number of asterisks that is requested by input. I…
-
0
votes1
answer156
viewsHow to show 5 in 5 hidden elements?
I was struck by a doubt recently, by which I must manipulate a certain number of elements hidden through the display:none; that it is defined on the span that involves all of them. Example…
-
0
votes1
answer1857
viewsCreate JSON with javascript
I wanted to know how to create a json by taking data from another json using a for var imdb = { "title": "Justice League", "content_rating": "PG-13", "original_title": "", "metadata": { "languages":…
-
0
votes0
answers151
viewsMultiple requests with ajax - Jquery
I have a page containing 1 (one) to 50 requests. So I use a loop that makes the call. By the speed of my internet, in a matter of 3 seconds I should upload all the requests. But it’s done one by…
-
0
votes2
answers332
viewsCalculation of the smallest divisible number giving infinite loop in C
I did a C program to solve the following exercise: Code: #include "stdio.h" #include "stdlib.h" int main(int argc, char const *argv[]) { int num = 0; int count = 20; int contaDivisores = 0; for(int…
-
0
votes3
answers376
viewsmultiply div s repeat loop co div s
I have a list of channel names that are broadcasting a certain game on twitch.tv (api), so I can take all the channels and list the same. The question is how to put them in a div To stay in blocks…
-
0
votes1
answer547
viewsPython to turn a number into an integer
import math x=9 raiz=math.sqrt(x) print raiz for i in range (raiz,9): #Problema aqui i=i**2 print i I need to create a for with the root of an operation (always whole. 2, 3,4,5...) but when I try to…
-
0
votes1
answer64
viewsAnimation to decrease the size of a cube in Unity
Hello! I’m in Unity using C# and I have a cube that, when I press q, it drops to 0.5 scale from scale 1 and when I drop q, he goes back to scale 1. I wanted there to be some quick animation of the…
-
0
votes1
answer207
viewsTreat multidimensional array in Angularjs
I have that function: getProducts(){ this.auth.getProducts().subscribe(data => { this.turmas = []; this.produtos = []; this.cursos = []; for (var i = 0; i < Object.keys(data).length; i++ ) {…
-
0
votes1
answer155
viewsHow to print on screen or console, a string array in php
I’ve been going through the documentation, but it’s unclear how I do it. I have an array of strings: $remetente = $con->real_escape_string($_REQUEST['rem']); $arrai= array(); $remetenteArray[] =…
-
0
votes0
answers188
viewsstruct that stores the number of rows and columns of the matrix and of a vector
I used a struct to store the number of rows (m) and columns (n) of the matrix and another to store the number of columns of the vector (n). I make the product of two matrices in function prod() and…