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
-
38
votes2
answers1031
viewsWhy use "while(0)"?
In Linux code I saw some macros with: do { }while(0) Is there a reason? Because there seems to be no logic in a repeat loop where the code repeats only once.
-
27
votes12
answers28737
viewsWhat are the ways to iterate an array in PHP (without foreach)?
Before I am censured by the question, notice beforehand that the purpose of it is simply to level curiosity. I know that the foreach is the most suitable means for this. But I would like to know the…
-
21
votes3
answers1786
viewsWhat is the usefulness and importance of "do... while"?
The command while is a repeat structure with a condition at the beginning of the declaration. Example: while (condição) { sentenças a executar } Already do...while has verification at the end, ie…
algorithm loop characteristic-language while do-whileasked 9 years, 3 months ago Denis Caixeta 3,427 -
20
votes8
answers17275
viewsDifference between while and for
What’s the difference between while and for, if the two are loops of repetition, if with the two I can do the same things either conditioning a halt or iterations of variable, because there are…
-
16
votes3
answers9258
viewsWhat good is while(0) and while(1) in C?
What is the purpose of this? While(0) or While(1). Does 1 verify that it is correct and 0 that is wrong? Why?
-
14
votes3
answers19255
viewsWhat is the difference between while, for, while and foreach?
What is the difference between the while , do while, for and foreach in PHP, because they give the impression that same functionality. All of them can be used to create a loop or has other purposes?…
-
12
votes4
answers299
viewsWhat does the "do" function do in Javascript?
I searched a lot and I can’t find the functionality of do in Javascript. Example: function b(a, b) { do a = a[b]; while (a && 1 !== a.nodeType); return a }…
-
10
votes3
answers2257
viewsWhich loop is faster in C: while or for?
Being a bond while and a for that run the same number of times, which is faster? Example: while: int i = 0; int max = 10; while(i<max){ funcao(); i++; } for: int i; int max = 10; for(i=0;…
-
8
votes3
answers1135
viewsHow to make the first two numbers of a sequence Math.Andom are NOT EQUAL
I made a lottery system in order to learn, I will not post the entire code here just the part I’m stuck. The PC draw is a sequence of 6 numbers that I present in the DOM (that doesn’t matter), so I…
-
8
votes1
answer1772
views -
8
votes4
answers763
viewsWhat would be a good way to apply events: onMouseOver and onMouseOut, for all img tags?
I need this function to be automated so that it applies to all images built on the HTML document without any exception Code function aumenta(obj) { obj.height = obj.height * 2; obj.width = obj.width…
-
7
votes2
answers260
viewsIs there any difference between an infinite loop with for and while?
In PHP, it is possible to generate a loop infinity with while simply passing the parameter true. Example: while (true) { echo "Ao infinito e além"; } It is also possible to generate this through…
-
7
votes1
answer105
viewsIs there an alternative to multiple while loops?
I have a method alterar() that change the data of a particular element of my XML Person, however, this routine uses several whiles one for each element, see below the routine: public void alterar()…
-
7
votes1
answer275
viewsWhat is the purpose of while(*variable) and if(!*variable) in the statements "while" and "if"?
In Code Review there is a implementation of a simply chained list that I am using. However, in the reply of one of the users, he made some modifications to the list, and had a particular…
-
7
votes3
answers557
viewsContinue loop if input is’S'
I tried to make a loop, that while the input is’S' it comes back and prompts again (it’s just for me to learn), if the input is 'N' it comes out of the loop, but is in loop infinite. continuar =…
-
6
votes2
answers1244
views -
6
votes3
answers342
viewsWhy doesn’t the while stop?
#include <stdlib.h> #include <stdio.h> int main() { int i,j; char elenco[30]; while(elenco[i]!='s' || i<=20) { printf("indique um menbro do elenco ,se quiser sair escreva apenas a…
-
5
votes4
answers599
viewsProgram Locking in While
I’m working on a project and I’m having problems with the same, this program I’m posting is similar to what I’m working on. The problem is this: it arrives in while, the program does its function,…
-
5
votes2
answers135
viewsWhile with incomprehensible format
My knowledge in java is very basic, before that I came across a question to which I have not found answer. The code snippet below is used in some of my applications: File arquivo = new…
-
5
votes1
answer605
viewsClose loop when typing specific character
Hello! I need to resolve the following question, but I’m not getting it. Write an algorithm that calculates the average arithmetic of the students' 3 grades (number undetermined of pupils) of a…
-
5
votes5
answers1513
viewsSkip Record within a while
I wonder how it is that I jump a log inside a while? For example, when the guy is 2 he jumps while($pessoa = mysqli_fetch_object($query)){ if($pessoa->tipo == 2){break;} //continua a exibição de…
-
5
votes1
answer64
views -
5
votes2
answers181
viewsSimple ways to break a *while* with a function
I usually run into this problem: while True: input_chute = int(input("chute: ")) if input_chute == 0: break bla bla bla ... In that example above I break while with a condition and a break, however,…
-
5
votes1
answer117
viewsLoop Error in R
I created this loop: library(forecast) a=1 b=60 while(b<=(NROW(tsarroz))){ janela=dput(tsarroz [a:b]) serie=ts(janela,freq=6) HW=HoltWinters(serie) prev=forecast(HW,6)…
-
4
votes3
answers4312
viewsHow the end of file loop is done
Type, I know that the function feof() returns 0 if it did not find a file end and that it requires 1 parameter, which is the pointer_pra_variável_tipo_FILE, so far so good. If I do the while so it…
-
4
votes3
answers441
viewsWhy is it not very common to use do/while?
I don’t know if this occurs only in PHP, but I realize that it is not very common the use of do/while in the codes written on it. Example: while (ob_get_level() > 0) { ob_end_clean(); } That (I…
-
4
votes1
answer299
viewsHelp with PHP repeat structure - PARSER - simple_html_dom.php
I’m doing a parser with simple_html_dom.php where I pull all the links from a given page. I can pull the links and assign to an array, here comes the problem: this page has a maximum display limit…
-
4
votes2
answers1313
viewsC++ - Stop condition in repeat structure
How to put this code in a repeat structure so that after the calculation is shown the option "Type S to exit or C to continue"? #include <iostream> #include <string.h> #include…
-
4
votes1
answer73
viewsWhat error in while loop? moon turn on
What’s the error in the loop? I wrote this code to print the sum of the first 10 prime numbers, I’ve reviewed the loops but I couldn’t find the error. It was to print the sum of the cousins until 29…
-
4
votes1
answer335
viewsGoogle Chart’s Line with While
Good afternoon, I have the following appointment: SELECT DATE(o.data_fechamento) AS Data, u.nome AS Pessoa, COUNT(*) AS Total FROM ocorrencias AS o LEFT JOIN sistemas AS a ON a.sis_id = o.sistema…
-
4
votes0
answers57
viewsEM algorithm error with while loop
Hello, my project needs the EM algorithm below, where are all the codes. The error is in the loop while, which is where the hope and maximization steps are. The error message is: "Error in while…
-
4
votes1
answer97
viewsDoubt with While
I’m a beginner and I’m having second thoughts While / Do…While, follows the doubt in which question. I have an exercise to follow that the teacher solved with the command Do…While, I was trying to…
-
3
votes2
answers269
viewsProgram always returns the same result in C
The code runs normal but only one way out: sunday! regardless of the number chosen. What the programme should do Implement a program with an input number (1-7) which corresponds to one of the days…
-
3
votes4
answers1123
viewsNext record. PHP + Mysql
I am a beginner in programming and would like to know how I would make mine $id = 1, turn 2, 3 and so on. The code at the end, means that it needs to compare that value and only then occurs a $id++.…
-
3
votes3
answers363
viewsJavascript function does not respect loop conditions
Good afternoon, I’m new here and I’m using the Javascript Scratchpad of Mozila Firefox to execute codes Javascript. It will really meet my needs, however the stop condition of the while loop is not…
-
3
votes2
answers249
viewsDo While enters infinite loop
I’m sure my mistake is in while, but I can’t understand what I did wrong. He goes into loop infinite. Follows the statement: Implement a program that receives 3 arguments from the command line. The…
-
3
votes1
answer385
viewsI’m not getting loops while nested
I’m having trouble understanding this code, because I don’t understand how it behaves in loops while, follow the instructions after the code. Note 1: I am learning programming logic yet, so I am…
-
3
votes3
answers85
viewsHow does variable p work in this code?
I don’t know how the variable p of loop while is working on that code. If the variable p is the iteration variable, because the exercise also uses a variable p within the while to store the s.find(…
-
3
votes1
answer84
viewsEliminate code redundancy in a while loop
In this example: . Request today’s date via a form. . Check if typed in dd/mm/yyyy format. . Compare to current system date from datetime import date def verificacaoData(): dataForm = input('Digite…
-
3
votes2
answers165
viewsVariable appears as undeclared when trying to use it in the "while" loop
When trying to create a program that converts Celsius into Fahrenheit to get practical and I come across the following error message: Erro "sair " undeclared (first use in this function) My…
-
3
votes1
answer77
viewsConfirmation code
I wanted to make a scheme to confirm a question. If the answer was Yes to the question, an ok message would appear. If it was No or different from Yes, I would ask if the person would like to…
-
3
votes2
answers295
viewsProper use of while to validate data entry
I’m trying to apply a repetition using the while also using the IF condition, which returns a message to the user if they enter an invalid value. Note that I write nothing inside the while, but the…
-
3
votes1
answer56
viewsDoubt with the counter at the while
Analyzing this code that serves to calculate arithmetic progression and that is working correctly: primeiro_termo = int (input ('Primeiro termo: ')) razao = int (input ('Razão: ')) contador = 1…
-
2
votes1
answer604
viewsStore Variable within a While
I’m having a simple doubt but it’s cracking my head: I have a form where there are several checkbox, the checkbox value is an id number, I would like to create something that when the user selects a…
-
2
votes2
answers126
viewswhile code does not make the correct condition
I need to create a code that reads only one double and register in two variables the "smallest so far" and the "biggest so far", I can even complete a cycle successfully but after that it prints out…
-
2
votes2
answers871
viewsListing images within a directory
I want to list the images from a directory, but I’m not getting it. You’re listing the right amount and everything, but the images don’t appear. <?php $path =…
-
2
votes2
answers6548
viewsJavascript function calling another javascript function inside a while
I’m having a problem executing a javascript function that in its scope has a while that according to how the counter is incremented, is called a second javascript function passing as parameter the…
-
2
votes2
answers186
viewsConvert File Names to Alphabet Letters
Convert File Names to Alphabet Letters For example, I have several image/photo files in a directory, and I want to pass these long names of the respective images in names designated by letters of…
-
2
votes1
answer1420
viewsdo the multiplication of values using sum operator and while
var n1 = Number(window.prompt(" digite o primeiro número ")); var n2 = Number(window.prompt(" digite o segundo número ")); var soma; var num = 0; while( num…
-
2
votes2
answers452
viewsLogic PHP: how to build this looping (for, while, foreach)?
Good night. I am in the following situation: I am reading an XLS and playing in table. This XLS has 52 rows and 6 columns. What I’m picking up to do is: $result[linha 1][coluna A] $result[linha…