while-loop Questions
15
Solved
I am learning java as well android. Almost everything that we can perform by while loop those things we can do in for loop.
I found a simple condition where using while loop is better than for lo...
Broadway asked 15/7, 2011 at 17:0
23
Solved
I often use this code pattern:
while(true) {
//do something
if(<some condition>) {
break;
}
}
Another programmer told me that this was bad practice and that I should replace it wit...
Tennison asked 24/12, 2008 at 0:28
8
Solved
Why do some people use while(true){} blocks in their code? How does it work?
Signac asked 16/10, 2010 at 0:23
8
Solved
Can you please tell me how does this java code work? :
public class Main {
public static void main (String[] args) {
Strangemethod(5);
}
public static void Strangemethod(int len) {
while(len...
Gunsel asked 18/6, 2010 at 14:57
13
I've noticed the following code is legal in Python. My question is why? Is there a specific reason?
n = 5
while n != 0:
print n
n -= 1
else:
print "what the..."
Many beginners accide...
Trilogy asked 21/7, 2010 at 2:49
3
Solved
In Java it is possible to declare a variable in the initialization part of a for-loop:
for ( int i=0; i < 10; i++) {
// do something (with i)
}
But with the while statement this seems not to...
Bloodred asked 4/8, 2016 at 12:7
5
Is there a pattern in C to execute a while loop one more time.
Currently I'm using
while(condition) {
condition = process();
// process() could be multiple lines instead of a function call
// s...
Unlive asked 6/4, 2015 at 16:25
4
Solved
I've written a function trailing_zeroes(int n) that returns the number of the trailing zeroes in the binary representation of a number.
Example: 4 in binary is 100, so the function in this case ret...
Castellany asked 20/7, 2017 at 17:52
6
Solved
I am using grep in a while loop to find lines from one file in another file and saving the output to a new file. My file is quite large (226 million lines) and the script is taking forever (12 days...
Grijalva asked 2/1, 2023 at 14:12
15
I am a python newbie and have been asked to carry out an exercise: make a program loop until exit is requested by the user hitting <Return> only. So far I have:
User = raw_input('Enter <Ca...
Barmen asked 31/8, 2011 at 10:7
5
Solved
I've seen a bunch of answers on JS about an infinite loop and I thought that it would help for my code but it doesn't seem to be working properly.
I have that:
var i = 0
while (true) {
setTimeo...
Rectum asked 6/8, 2017 at 11:45
7
Solved
I have a while loop, and I want it to keep running through for 15 minutes. it is currently:
while True:
#blah blah blah
(this runs through, and then restarts. I need it to continue doing this e...
Commutual asked 23/6, 2014 at 20:17
4
This is a very simple dice roll program that keeps rolling two dice until it gets double sixes. So my while statement is structured as:
while DieOne != 6 and DieTwo != 6:
For some reason, the prog...
Thingumabob asked 12/1, 2019 at 19:31
5
Solved
I need help with a program in python 3.3 that is supposed to do Russian peasant multiplication/ancient Egyptian multiplication. The assignment says," If "A" and "B" are the two integers to be multi...
Caramelize asked 1/2, 2013 at 1:7
6
Solved
This script breaks up the cvs list into three columns.
we are focusing on the "name" column. I want to discover the name that has the most characters. Once I find the name with the most characters...
Flinn asked 3/11, 2017 at 1:36
3
Solved
There are a number of different way to accomplish the same simple loop though the items of an object in c#.
This has made me wonder if there is any reason be it performance or ease of use, as to ...
Tonguing asked 6/3, 2013 at 12:22
6
Solved
I want to have a while loop do something like the following, but is this possible in c++? If so, how does the syntax go?
do {
//some code
while( expression to be evaluated );
// some more code...
Sweetmeat asked 27/11, 2009 at 6:33
4
Solved
I'm trying to generate a list of string dates in months
(i.e. ["Oct 2014", "Nov 2014",... "Jan 2015" ])
using the code here:
var resultList = [];
var date = new Date("October 13, 2014");
var en...
Tensile asked 14/1, 2015 at 3:12
8
Solved
I have read the relevant pages on w3schools and other similar questions here but cannot seem to understand what's wrong about the following bit :
var myfunc03 = function (i) {
document.getE...
Cristie asked 9/6, 2016 at 14:2
3
Why can't while loop be used on a range function in python ?
The code:
def main():
x=1;
while x in range(1,11):
print (str(x)+" cm");
if __name__=="__main__":
main();
executes as an infi...
Transom asked 5/4, 2018 at 17:13
2
Solved
I have written this:
while file.readline().startswith("#"):
continue
But I suspect the continue is unnecessary? What is the correct syntax for what i'm trying to achieve?
Unbiased asked 10/2, 2013 at 11:6
4
Solved
In Python you have two fine ways to repeat some action more than once. One of them is while loop and the other - for loop. So let's have a look on two simple pieces of code:
for i in range(n...
Kugler asked 15/7, 2013 at 6:22
5
Solved
I apologize if this a stupid question, but I cannot find the answer anywhere.
How does the following code work? (I realize that it loops over the elements of els)
var i = els.length;
while (i --&...
Rhyolite asked 24/12, 2013 at 3:48
6
Solved
I have this code and I want to catch the letter exception but it keeps having these errors:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:...
Depth asked 29/5, 2013 at 14:12
13
Solved
I'd like to write a java while loop that will iterate for 15 seconds. One way I thought to do this would be to store the current system time + 15sec and then compare that to the current time in the...
Somatoplasm asked 8/1, 2010 at 16:46
© 2022 - 2024 — McMap. All rights reserved.