while-loop

Access variable inside while loop from outside (C#)?

陌路散爱 提交于 2019-12-18 09:10:48
问题 I'm New to C# and I'm trying to reach the value of MAX from the while so i can use it outside but i can't...anyone have some ideas !!! Thanks In Advance while (Condition) { Double MAX = somecode..... ..... } Console.WriteLine("The OPTIMAL Value : " + MAX); 回答1: Declare MAX before you start the while loop. The way you have it you can only access within the while. Double MAX = 0; while (Condition) { MAX = somecode..... ..... } Console.WriteLine("The OPTIMAL Value : " + MAX); 回答2: You must

Progress bar while running while loop

雨燕双飞 提交于 2019-12-18 09:05:28
问题 I have this while loop, that basically loops through a lot of records in a database, and inserts the data in another: $q = $con1->query($users1) or die(print_r($con2->errorInfo(),1)); while($row = $q->fetch(PDO::FETCH_ASSOC)){ $q = $con2->prepare($users2); $q->execute(array($row['id'], $row['username'])) or die(print_r($con2-errorInfo(),1)); } (The script has been shortened for easy reading - the correct one has a much longer array) I would like to do this more graphical, and show a progress

Comparing two files in java

风格不统一 提交于 2019-12-18 07:24:30
问题 I am trying to compare two .txt files (i.e their contents), but when I execute this code my application goes into an infinite loop. Why? public int compareFile(String fILE_ONE2, String fILE_TWO2)throws Exception { File f1 = new File(fILE_ONE2); //OUTFILE File f2 = new File(fILE_TWO2); //INPUT FileReader fR1 = new FileReader(f1); FileReader fR2 = new FileReader(f2); BufferedReader reader1 = new BufferedReader(fR1); BufferedReader reader2 = new BufferedReader(fR2); String line1 = null; String

echo problems in PHP

◇◆丶佛笑我妖孽 提交于 2019-12-18 07:05:08
问题 I dont know how to repost questions so im just gonna link my old post here some item won't echo after putting some condition in php although some problems were solved there thanks to @Shinkou, there are still errors found in my program.I tried to figure out what caused this problem but i found no luck in solving them. now let me tell you what my program does.i have 2 admins with different functions. the admin uploads file,and registers a new company and employee detail.he is also responsible

try block inside while statement

江枫思渺然 提交于 2019-12-18 06:59:24
问题 I'm just starting out with Python 2.7 and I don't understand why something is happening: In the following code, an embellished version of an example from the python 2.7.2 tutorial, I get an unexpected result: while True: try: x = int(raw_input("Please enter a number: ")) break except ValueError: print "Oops! That was not a valid number. Try again..." else: print 'Thanks,',x,'is indeed an integer' finally: print 'all done, bye' When I put in an integer, the code ignores the else: statement and

What does while (i --> 0) mean?

怎甘沉沦 提交于 2019-12-18 05:12:40
问题 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 --> 0) { var el = els[i]; // ...do stuff... } I have no idea what --> means. There is no documentation for it. Can someone enlighten me? 回答1: It should be read as i-- > 0 So, what really happens is, value of i will be checked if it greater than 0, if it is true then control will enter the while block,

setTimeout inside while loop

狂风中的少年 提交于 2019-12-18 05:02:28
问题 I've searched for how to use setTimeOut with for loops, but there isn't a lot on how to use it with while loops, and I don't see why there should be much difference anyway. I've written a few variations of the following code, but this loop seems to crash the browser: while(src == '') { (function(){ setTimeout(function(){ src = $('#currentImage').val(); $("#img_"+imgIdx).attr('src',src); }, 500); }); } Why? Basically I have an image created dynamically whose source attribute takes time to load

What is the difference between infinite while loops and for loops?

可紊 提交于 2019-12-18 04:59:11
问题 I see the different conventions used in many books I had read, where you would create infinite loops with either loop structure such as: while() foo(); for(;;) foo(); But really, what are the differences I should know about? which one is better? 回答1: They're semantically the equivalent. (x;y;z) { foo; } is equivalent to x; while (y) { foo; z; } . They're not exactly equivalent in further versions of the standard, in the example of for (int x = 0; y; z) , the scope of x is the for block and is

Python Assign value to variable during condition in while Loop

纵然是瞬间 提交于 2019-12-18 04:31:43
问题 A simple question about Python syntax. I want to assign a value from a function to a variable during the condition for a while loop. When the value returned from the function is false, the loop should break. I know how to do it in PHP. while (($data = fgetcsv($fh, 1000, ",")) !== FALSE) However when I try a similar syntax in Python I get a syntax error. 回答1: You cannot use assignment in an expression. Assignment is itself a statement, and you cannot combine Python statements. This is an

variable declaration within the while loop C/C++

霸气de小男生 提交于 2019-12-18 04:24:18
问题 according to me following while loop should be infinite but it runs only thrice main() { int i=3; while(i--) { int i=100; i--; printf("%d..",i); } } it outputs 99..99..99 but according to me it should run infinite times as every time control enters while loop it gets value 100.so it will never reach zero. just to experiment i replaced int i=100; with i=100; in side the while loop and now it runs infinite times..WHY??? 回答1: The variable i that checks the condition is the one you declared in