while-loop

Table variables inside while loop not initializing everytime : SQL Server

空扰寡人 提交于 2019-12-05 10:15:48
I am wondering why the table variables inside while loop does not behave like other variables. Table variables created only once and will be used across through out whole looping. but other variables getting initialized every time when loop increases. Check out the below code for more info declare @tt int set @tt =10 while @tt>0 begin declare @temptable table(id int identity(1,1),sid bigint) insert into @temptable select @tt union all select @tt + 1 select * from @temptable --delete from @temptable set @tt=@tt-1 end is this a bug?? Your premise is wrong. Other variables don't get reinitialised

J: Why does `f^:proposition^:_ y` stand for a while loop?

孤人 提交于 2019-12-05 10:15:02
As title says, I don't understand why f^:proposition^:_ y is a while loop. I have actually used it a couple times, but I don't understand how it works. I get that ^: repeats functions, but I'm confused by its double use in that statement. I also can't understand why f^:proposition^:a: y works. This is the same as the previous one but returns the values from all the iterations, instead of only the last one as did the one above. a: is an empty box and I get that has a special meaning used with ^: but even after having looked into the dictionary I couldn't understand it. Thanks. f^:proposition^:_

PostgreSQL: Loop Until a Condition is True

两盒软妹~` 提交于 2019-12-05 09:59:16
I am trying to write a query which "loops" through a database starting at a specified value until a condition is true. For example, suppose I have the following entries in TABLE example: id, parent, cond 1, , True 2, 1 , False 3, 1 , False 4, 2 , False ... ... ... I want a query which takes as input (for instance) 4, and will return the values of 2 and 1. The process being that the query matches the id, and if cond==False, will look at the parent (id = 2). Since cond = False in the second row, the "parent" id will be selected (1). Looking at the first row now, since cond=True, the LOOP ends

Perl: Read web text file and “open” it

元气小坏坏 提交于 2019-12-05 09:44:10
I'm trying to create a script that will read text files and then analyse them, regardless of whether the text file is online or offline. The offline part is done, using open(FILENAME, "anyfilename.txt") analyze_file(); sub analyze_file { while (<FILENAME>) {analyze analyze} } Now for the online part, is there anyway to read a text file on a website and then "open" it? What I hope to achieve is this: if ($offline) { open(FILENAME, "anyfilename.txt") } elsif ($online) { ##somehow open the http web text so that I can do a while (<FILENAME>) later } analyze_file(); sub analyze_file { while (

Infinite loop problem with while loop and threading [duplicate]

寵の児 提交于 2019-12-05 08:27:36
This question already has an answer here : Loop doesn't see value changed by other thread without a print statement (1 answer) Closed 5 years ago . Using a basic example to illustrate my problem I have 2 near-identical bits of code. This code causes the while loop to run infinitely. private boolean loadAsset() { new Thread(new Runnable() { @Override public void run() { // Do something loaded = true; } }).start(); while (!loaded) { // System.out.println("Not Loaded"); } System.out.println("Loaded"); return false; } This code however (i.e. doing something in the while loop) causes the loaded

My cin is being ignored inside a while loop

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 08:12:52
I am trying to code a simple question and number checker into my first C++ program. Problem is, when I type a string like one two, or three, the program becomes and infinite loop and it ignores the cin function to re-assign lives to a number. cout << "How many lives would you like 1 (hard), 2 (medium), or 3 (easy)?" << endl; cin >> lives; while(lives != 1 && lives != 2 && lives != 3 && !isdigit(lives)) { cout << "You need to input a number, not words." << endl; cout << "How many lives would you like 1 (hard), 2 (medium), or 3 (easy)?" << endl; cin >> lives; } Here is my current code with your

While loop not ending when flag changed in different thread [duplicate]

一笑奈何 提交于 2019-12-05 05:53:11
This question already has an answer here: Loop doesn't see value changed by other thread without a print statement 1 answer I have a while loop running in my Java program's main method. The loop is supposed to run until a boolean flag variable is set to true in the program's keyPressed method (I added the program as a KeyListener to a JFrame). import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; public class ThreadWhile implements KeyListener { private boolean flag = false; public static void main(String[] args) { //Set up key listening on a dummy

Please code review my sample Python program [closed]

痴心易碎 提交于 2019-12-05 05:05:40
I'm still learning Python as I want to teach the essential concepts of the language to eleven year old kids (I work as a teacher). We have done a bit of work in basic so they understand the essentials of programming and breaking down tasks into chunks and such like. Python is the language that is going to be taught all across the UK with the new curriculum coming in and I don't want to teach the kids bad habits. Below is a little program that I have written, yep I know it's bad but any advice about improvements would be very much appreciated. I am still plowing through tutorials on the

PHP - Multiple while($row = mysql_fetch_array($variable)) { } ERRORS

两盒软妹~` 提交于 2019-12-05 05:00:32
Okay my syntax can probably be described without the code. Basically it should be easy...but never is. I have 2 loops in a row...basically the same thing. I SELECT * every variable from my database, and then I need to build a 2 layer javascript based on two sep. variables. So I have: while ($row = mysql_fetch_array($myVariable)) { // do events } then after that while ($row2 = mysql_fetch_array($myVariable)) { // do events } For some reason it's completely returning NOTHING on the second one...is there some where I need to reset my array, did it possibly end and then I can't just restart. Such

Interrupted exception vs isInterrupted in a while loop

a 夏天 提交于 2019-12-05 04:36:28
问题 Assume that I have the following code: while(!Thread.currentThread().isInterrupted()){ //do something Thread.sleep(5000); } Now Thread.sleep throws `InterruptedException so it should be like this: while(!Thread.currentThread().isInterrupted()){ //do something try{ Thread.sleep(5000); } catch(InterruptedException e){ } } If I hit the catch will the while loop continue or do I need to do Thread.currentThread().interrupt() ? If I do call this method, won't that also cause an InterruptedException