while-loop

how do an infinite loop in javascript

你离开我真会死。 提交于 2021-02-05 12:35:35
问题 Im trying to do an infinite loop using while between 0 to 100 and 100 to 0, but the browser crashes. There is a way to clear the browser memory? This is my code: var a = 0; var flag = true; while (true) { if (a < 100 && flag == true) { a++; } else { a = 0; flag = false; if (a < 0) { flag = true; } } console.log(a); } 回答1: An infinite while loop will block the main thread wich is equivalent to a crash. You could use a selfcalling function ( wich leaves the main thread doing some other stuff

Python - previous list elements being overwritten by new elements during while loop

我只是一个虾纸丫 提交于 2021-02-05 12:31:07
问题 Hello I am new to Python and am trying to figure out why my list overwrites the previous elements every time a new page is loaded and scraped during the while loop. Thank you in advance. def scrapeurls(): domain = "https://domain234dd.com" count = 0 while count < 10: page = requests.get("{}{}".format(domain, count)) soup = BeautifulSoup(page.content, 'html.parser') data = soup.findAll('div', attrs={'class': 'video'}) urls = [] for div in data: links = div.findAll('a') for a in links: urls

Python - previous list elements being overwritten by new elements during while loop

ぃ、小莉子 提交于 2021-02-05 12:30:41
问题 Hello I am new to Python and am trying to figure out why my list overwrites the previous elements every time a new page is loaded and scraped during the while loop. Thank you in advance. def scrapeurls(): domain = "https://domain234dd.com" count = 0 while count < 10: page = requests.get("{}{}".format(domain, count)) soup = BeautifulSoup(page.content, 'html.parser') data = soup.findAll('div', attrs={'class': 'video'}) urls = [] for div in data: links = div.findAll('a') for a in links: urls

PHP counter increment in a while loop

你离开我真会死。 提交于 2021-02-05 12:19:17
问题 Im having a problem incrementing a counter in one of my while loops basically i just want to alternate between two image links that were fetched in my database but my counter wont increase and im not sure why can anyone help? while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $img_link = $row['Image']; $img_link_alt = $row['Image_alt']; $i = 0; echo '<div class="col-xs-6 col-sm-3 placeholder">'; $img = ( $i % 2 == 0 ) ? $img_link : $img_link_alt; echo $i; //'?' . date("h:i:sa").' echo '<img style

C language Changing For Loop to While loop

旧城冷巷雨未停 提交于 2021-02-05 11:53:41
问题 How to make for loop to while loop Is it possible to change for loop in array to while loop ? change for(i = 0; i < 12; ++i) //for loop for selecting only positive { if(a[i] > 0) printf("%d ", a[i]); //display positive only using if statement } to int i = 0, a[12]; while(i < 12) { if(a[i] > 0) { printf("%d ", a[i]); } i++; } but it doesn't display the positive same as the negative if changed.. 回答1: int i; for(i=0; i < count; i++) { // Work item here } is functionally equivalent to int i=0;

Bash while loop ends execution when “ssh” is in loop body

放肆的年华 提交于 2021-02-05 10:37:48
问题 Could anyone of you explain why the following bash while loop ends execution after the first iteration when ssh is executed in it's body, please? Input file : $ cat hosts 192.168.223.21 miner01 192.168.223.23 miner03 While without ssh - two iterations: $ while IFS=' ' read -r IP HOST; do echo "ip=$IP hostname=$HOST"; done < hosts ip=192.168.223.21 hostname=miner01 ip=192.168.223.23 hostname=miner03 $ While with ssh in body - one iteration : $ while IFS=' ' read -r IP HOST; do echo "ip=$IP

Why does while (true) skip cin when it received invalid input? [duplicate]

霸气de小男生 提交于 2021-02-05 08:47:27
问题 This question already has answers here : cin input (input is an int) when I input a letter, instead of printing back incorrect once, it prints correct once then inc for the rest of the loop (2 answers) Closed 1 year ago . This while-loop does not wait for input from cin after receiving wrong input (non-integer). Does cin somehow stay in a false state? while (true) { int x {0}; cout << "> "; cin >> x; cout << "= " << x << endl; } I would expect this while-loop to wait for input everytime

How to output the decimal in average?

梦想与她 提交于 2021-02-05 08:36:29
问题 I have a problem in showing the decimals on the average. It keeps showing .00 or .1. I tried to put it in double, but I still get the same results.Also, I want to include the first integer that I input to the sum, but I have no idea how.Please help: import java.io.*; import java.util.*; public class WhileSentinelSum { static final int SENTINEL= -999; public static void main(String[] args) { // Keyboard Initialization Scanner kbin = new Scanner(System.in); //Variable Initialization and

Python break function doesn't end while true

断了今生、忘了曾经 提交于 2021-02-05 07:46:17
问题 Why will the break not end the while true and return to the start? while True: print('This is a quiz') print('What is your name?') Name = input() print('Hello ' + Name + ', The quiz will now begin') import time time.sleep(2) question1 = "Question one: " answer1 = "True" and "true" print(question1) qanswer = input() if qanswer != answer1: print('Sorry, the answer is: ' + answer1) break if answer1 == qanswer: print("Correct! Here's the next question") I'm pretty new to python so I assume it's

Possible to have multiple while (cin>>input)

两盒软妹~` 提交于 2021-02-04 21:49:43
问题 I would like to know if it's possible to have multiple while (cin>>(variable)) as in the following code: #include <iostream> #include <vector> using namespace std; int main() { vector<int> v1, v2; int input; while (cin>>input) v1.push_back(input); while (cin>>input) v2.push_back(input); return 0; } The logic of my program is to let user define the number of elements and value of each element in two sets of int vectors. However, I realized that after entering the first set of numbers for the