Most voted "while" questions
Use this tag when the question primarily involves logic and/or command structure. Effectively, while is a repeat loop used to iterate matrices, vectors, or to another end that basically has a single component, the stop condition.
Learn more…332 questions
Sort by count of
-
2
votes1
answer4995
views -
2
votes3
answers160
viewsFunction prints while list
How do I do this function with the loop while? void imprime(lista* recebida){ lista* aux; for(aux=recebida; aux!=NULL; aux=aux->prox){ printf("Informacao %d\n",aux->info); } }…
-
2
votes2
answers153
viewsPrint number of nodes in a list
This code below does not work properly, I type 5 knots and was to return the number 5 (total amount of knots entered). It happens that returns me 4. int qtd_no_lista (tipo_lista * recebida) {…
-
2
votes2
answers399
viewsProblem with while repetition structure
I made this little code so he’d ask for a username and a password. If the data were the same as those defined within the code, show a "success", if the user is different from the one placed in the…
-
2
votes1
answer2293
viewsHow do I stop organizing tables in while?
How do I stop organizing this table ? Sum, subtraction and multiplication respectively ? #include <stdio.h> int main (){ int i=0, num=0; printf ("Digite um n£mero: "); scanf ("%d",&num);…
-
2
votes1
answer525
viewsMethod of choice with while
I have two options and the program should say which one was chosen, if the input is wrong should ask to repeat the request. Problems: Option 2 repeats 2 times until right. Option 1 does not say a…
-
2
votes1
answer53
viewsWhy use Kernel#loop instead of Begin-end-while/until?
I’m making a Ruby repetition structure using the following structure: begin [código] end <while/until> [condição] But the Rubocop, which I use as a tool for linting, says I should use the…
-
2
votes2
answers383
viewsSubtraction of arrays
I have two arrays: A AND B A = [1,2,3...] B = [7,5,1...] When I do this subtraction has the correct subtraction return: console.log(A[0] - B[0]); But when I play in the loop it doesn’t work: while…
-
2
votes1
answer88
viewsHow to interrupt a cycle of "whiles"?
Well, I’m going to give a very abstract example in order to be able to express my doubt more simply I have following code: while(a>b){ // Meu while principal while(c>d){ while(e>f){ } } }…
-
2
votes1
answer5400
viewspq the while True loop accesses if and Else in sequence to every complete loop in that code?
#! /usr/bin/python3 valor = int(input("Digite o valor a pagar: ")) cedulas = 0 atual = 50 apagar = valor while True: if atual <= apagar: apagar = apagar - atual cedulas += 1 else: print("%d…
-
2
votes6
answers7179
viewsSimple Solution for Fibonacci Algorithm
I have this statement in hand: Given the Fibonacci sequence 1 1 2 3 5 8 13 ... n, write an algorithm to generate the sequence to the nth term, which must be provided by the user. For example, if the…
-
2
votes1
answer113
viewsHow to change Cartesian file coordinates in an automated way
I have a certain folder with several files, and these in turn contain inside description of coordinates points cartesian X and Y. However, I want to replace these points automatically and…
-
2
votes1
answer87
viewsTable with 2 td with select inputs showing return only in the first row
I have 1 table with 1 list of modules, and I have 2 columns that have options that can be chosen through select. The point is that the select’s only load the data in the first row of the table, the…
-
2
votes2
answers471
viewsQuestion using while
I am new in java and would like a help from you, my code is correct following the exercise I am doing, but I want to increment it using while to ask the user if he wants to repeat the process of the…
-
2
votes1
answer51
viewsHow to do a while with 2 checks
I’m trying to get while to take 2 values to stop but it just doesn’t enter while, I’m starting programming so try to help in a simple way Objective of the code: To achieve the 0 of a function of 1…
-
2
votes1
answer54
viewsHelp with While in c++
I was curious about the following code in c++. int main(int argc, char** argv) { float n1,n2,n3,n4; int i = 1; char nomeAluno; printf("Digite seu nome: "); scanf("%s", &nomeAluno);…
-
2
votes1
answer55
viewsFactorization algorithm in C
When creating a number factor algorithm with while I see that by input of the number 21 onwards, the result is wrong -negative. #include <stdio.h> long int i=1, ii=1, num, fat=1, somatorio;…
-
2
votes2
answers45
viewsWhile is not loading the logs
I am trying to repeat a region however, although mysqli_num_rows indicates that there are 9 records, while nothing is coming. My code is like this: $qry = "SELECT pe_orclinhas.id_orclinha,…
-
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
votes2
answers98
viewsUsing PDO links in PHP
I am trying to create a loop with PDO where I can choose the desired field to position it on the page. But the code I’m using is bringing all the fields at once. My code is like this:…
-
2
votes3
answers2944
viewsWhile use within the if
I have to read infinite averages of students and if they are greater than or equal to 7 the student is approved , if not, he is flunked , and if I type -1 the program to and sends a message of…
-
2
votes3
answers122
viewsIteration using "while"
I have a little trouble understanding while and I came across an exercise that asked me to do the following: Read N sequences and find out how many f has in each sequence. I cannot use for in that…
-
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
votes2
answers106
viewsMake a game continue or stop as the player chooses
In this game the player chooses a limit number and from this limit will be drawn a number and the user needs to hit it, I’m doing with function, but I do not know how to call again if the user wants…
-
2
votes1
answer720
viewsHelp with simple while summation program
Gentlemen, I started to introduce the programming and the master is requesting an exercise as follows: Write a Python script that asks the user to enter an integer, n, and computes the sum 1 + 2 +…
-
2
votes1
answer107
viewsOperator problem not in the condition of a while loop
I made a program to train txt manipulation: def escreve(): BancodeDados = open("Base.txt", "a") continua=True k=1 while continua: nome = input("Nome do cliente: ") idade = input("Idade do cliente:…
-
2
votes2
answers54
viewsMy while isn’t stopping when the condition is true.. I type "VITOR" but can’t exit the WHILE
import java.util.Scanner; public class RepeticaoWhile { public static void main(String[] args) { String nome; System.out.println("Digite o nome VITOR…
-
2
votes1
answer26
viewsFilter two lines of the file at the same time show only the second?
I have the following fictional file: Location: Estado Title: Bahia Location: Estado Title: Pernanbuco Location: Estado Title: Alagoas Location: Cidade Title: Recife Location: Cidade Title: Barretos…
-
1
votes1
answer573
viewsSubcategory listing according to selected category
I have the following code snippet: <?php foreach($categorias as $cat){ $id_cat = $cat['id']; $subcategorias = array(); $sqlsub = Comando::Executar("SELECT * FROM subcategoria WHERE cat_pai =…
-
1
votes2
answers428
viewsHow to insert an array into a variable?
Realizing that it has a lot of repetitive code I decided to automate creating a looping of reading the cells of my excel file. #row cell fixa para o horario rows = ts[1].rows cells = rows[1].cells…
-
1
votes1
answer30
viewsThe Bitsnoop API is crashing WHILE
Hello, I’m using that API from Bitsnoop, but a part of it is "catching" WHILE. WHILE only runs once and nothing below it loads. Code: if($sql = mysqli_query($coneccao, "SELECT * FROM…
-
1
votes1
answer959
views -
1
votes2
answers208
viewsHow do I force entry into "while"?
This program allows to calculate the table from up to 10 to a given number x. But in the cycle of the while after the first iteration it does not enter and jumps to the end. For example, if I insert…
-
1
votes2
answers2013
viewsModal Bootstrap > While Loop > Open Modal Item
I believe it’s a matter of putting the code in the right place, but I’m racking my brain and I can’t... I made a test with the standard Bootstrap code, where it works on a button. I even put the…
-
1
votes1
answer3034
viewsAdding up positives in a range using only while
I need to write a program using loop (while) that receives two numbers as input, can be positive or negative and not necessarily in ascending order, and the program must print the sum of all…
-
1
votes0
answers216
viewsIs it good programming practice to write a while with true argument so that it runs endlessly?
In a hypothetical situation: Is it good programming practice to write a while that way? So that it continues to run endlessly? while(true){ System.out.println("Por favor, Escolha: ");…
-
1
votes3
answers729
viewsReceive two positive numbers and repeat the interval between them with while?
How to make a Javascript program that takes two positive numbers and repeats the interval between them using while? var num1 = Number(window.prompt("Entre com primeiro numero")); var num2 =…
-
1
votes1
answer43
viewsSimple While Cycles
#include <stdio.h> main(){ int cont=15; while(cont<=200){ printf("%d\n",&cont); cont++; } } Supposedly the counter should start with the value 15 and go showing its value by adding 1 at…
-
1
votes1
answer325
viewsProblem with While condition in C++
Hello, I’m studying from Bjarne’s book "PROGRAMMING Principles and Pratice Using C++". I’m trying to make Drill number one chapter four. The exercise tells you to make a program that consists of a…
-
1
votes1
answer440
viewsWhile Exercise for Proof
I can’t do this exercise, not with while or with gone. If you can make it available to me the way it’s done with While and For,. Given a list of numbers, tell us the highest number on the list. Use…
-
1
votes1
answer41
viewsPrint the previous 30
I have to print the 30 numbers previous to the number chosen by the user. while(valor > (30 - valor)){ System.out.println(valor); --valor; } I did so, but he does not print the previous 30,…
-
1
votes2
answers457
viewsWhy doesn’t my while work?
I’m studying repetition structure and in one of the exercises I had to check the sex typed, so I made the following code: sexo = input("digite m ou f: ") while sexo != 'f' or sexo != 'm': sexo =…
-
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
answer101
viewsWhile inside mail function
I have the following question: I want to get the results of a While (Basically 10 records), to be inserted inside the mail function. I don’t have a clue how I’m gonna do it, anyone can help me. 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
answers406
viewsMemory consumption in java
Good morning Personal. I made a java application that at certain times it executes a database query and generates a text file. The application is working right in the schedules that were programmed,…
-
1
votes1
answer100
viewsError while using while to generate barcode
First: I’m using the function below and am implementing a chile. Reason: need to generate several codes, example: 1 2 3 4 5 .... 98 99 100,follows code: <?php $i = 1; while ($i <= 100) {…
-
1
votes2
answers285
viewsWhere to use accumulators in a unique peer-review algorithm?
Where should I fit the accumulators of this code I have written for now? #include <stdio.h> int main() { int N; int somapar; int somaimpar; do{ printf("\n Digite um número qualquer: ");…
-
1
votes2
answers874
viewsWhat does while(x-) mean in C language?
I came across this code and didn’t understand the tie while(a--), what it means? int main(){ char pisca[10], a = 3; short numero; while(a--){ numero = 0; while(1){ scanf("%s caw", pisca);…
-
1
votes1
answer851
viewsArray counter with while in JS
I need to count the elements of a array using the loop while and display in a alert(), but is not exhibiting in the browser the count number. Using for worked out. I leave my code below: var deuses…