while-loop

replacing while loop with list comprehension

夙愿已清 提交于 2019-12-11 03:23:54
问题 It is common to express for loops as list comprehensions: mylist=[] for i in range(30): mylist.append(i**2) This is equivalent to: mylist = [i**2 for i in range(30)] Is there any sort of mechanism by which this sort of iteration could be done with a while loop? mylist=[] i=0 while i<30: mylist.append(i**2) i+=1 Of course with this simple example it's easy to translate to a for loop and then to a list comprehension, but what if it isn't quite so easy? e.g. mylist = [i**2 while i=0;i<30;i++ ]

setTimeout in loop to check for a change in bounds

被刻印的时光 ゝ 提交于 2019-12-11 03:09:36
问题 This is my code: var b; while(!b){ setTimeout(function(){ alert('sss') b=1; }, 500); } and it will not alert 'sss' What can i do? Updated: I want to get bounds on google maps v3: function get_bounds(){ var bounds_; while(!bounds_){ setTimeout(function(){ bounds_=map.getBounds(); if(bounds_){ var leftBottom=[bounds_.getSouthWest().lat(),bounds_.getSouthWest().lng()] var rightTop=[bounds_.getNorthEast().lat(),bounds_.getNorthEast().lng()] return [leftBottom,rightTop]; } }, 500); } } updated2:

Altering text in a .txt file and creating a new file output in MATLAB

非 Y 不嫁゛ 提交于 2019-12-11 02:44:30
问题 I apologize in advance if the title seems a bit off. I was having trouble deciding what exactly I should name it. Anyway, basically what I am doing now is completely homework that deals with low-level I/Os. For my one assignment, I have given two .txt files, one that includes a list of email addresses and another that includes a list members who no longer was to be on an email list. What I have to do is delete the emails of the members from the second list. Additionally, there may be some

bash while loop won't stop itself

China☆狼群 提交于 2019-12-11 02:26:19
问题 I got this simple script that is suppose to create a bunch of account numbers, it should take in two values: starting account number and how many accounts to create. Incrementing the account number as we go. So for example: ./pre_v_test.sh 123 3 should give 123 124 125 Right now it does that, with just one problem: it can't stop after it is done. the results look something more like this: .... Writing subsriber: 102145 lalala Writing subsriber: 102145 lalala Writing subsriber: 102145 lalala .

Infinite while loop with a random number

随声附和 提交于 2019-12-11 02:10:02
问题 I have this code: void generar() { while (true) { if (yPos == topOfTheWorld) { scene[xPos][yPos] = 2; } else if (yPos >= topOfTheWorld) { scene[xPos][yPos] = 1; } else if(yPos < topOfTheWorld) { scene[xPos][yPos] = 0; } else { scene[xPos][yPos] = 0; } yPos++; if(yPos>worldHeight) { topOfTheWorld += 0; yPos = 0; xPos++; } if (xPos>worldWidth) { break; } } std::ofstream output("mapa.txt"); for(int y=0;y<worldHeight;y++) { for(int x=0;x<worldWidth;x++) { output<<scene[x][y]; if(x<(worldWidth-1))

Use of kbhit() with while loop

百般思念 提交于 2019-12-11 02:01:56
问题 Here is the program. void main( ) { int h, v; h = 1; v = 10; while ( !kbhit( ) || h <= 80 ) { gotoxy( h, v ); printf( "<--->" ); delay( 200 ); clrscr( ); h = h + 1; } getch( ); } I am making a program in C, in which I have used kbhit() to run a loop until a key is pressed. so here the arrow "<--->" will keep on moving forward until a key is pressed or until it reaches the last pixel of the screen. What I want is that the program should increment h by 1 everytime 'd' is pressed and decrement

How can I exit a while(1) based on a user input?

寵の児 提交于 2019-12-11 01:46:50
问题 I have a simple server-client terminals. The server receives strings from the client and processes it. The server will only start processing once it receives the end_of_input character which in my case is '&' . The while loop below is meant to allow a user to input a number of different strings and should stop performing as it receives '&' . while(1) { printf("Enter string to process: "); scanf("%s", client_string); string_size=strlen(client_string); //I want to escape here if client_string

What are your tips for keeping track and avoiding bugs in loops?

泪湿孤枕 提交于 2019-12-11 01:20:00
问题 I just found ... AGAIN ... a real time wastage bug as follows for (int i = 0; i < length; i++) { //...Lots of code for (int j = 0; i < length; j++) { //...Lots of code } } Did you notice straight ahead the inner i which SHOULD BE j ? Neither did I. So from now on I am going to use: for (int i = 0; i < length; i++) { for (int i1 = 0; i1 < length; i1++) { } } What are your tips for inner and outer while and for loops ? Edit: Thanks for the valuable responses. Herewith short summary of the

Using a Loop Inside a Function

只谈情不闲聊 提交于 2019-12-11 00:46:56
问题 I'm still learning functions and how they work. I know what I'm doing wrong just not how to fix it. I am writing a function to pull image data out of a database and return it onto the screen. It works but if there is more than one image it will return the last image only. I know the problem is that $project_image is only returning the last image because of the way the while loop works but my question is how can i either not use a while loop or make it add more than one image to the $project

SQL WHILE Loops

假如想象 提交于 2019-12-11 00:07:29
问题 I have been working on creating a nested while loop in SQL, but having issues with the while loop. I think the main issue is with my outer loop. Any suggestions? USE HW_DB; IF OBJECT_ID('dbo.PythagoreanTriangles') IS NOT NULL DROP TABLE dbo.PythagoreanTriangles; GO CREATE TABLE PythagoreanTriangles ( Side1 INT NOT NULL, Side2 INT NOT NULL, Hypotenuse FLOAT NOT NULL ); DECLARE @side1 AS INT = 1; DECLARE @side2 AS INT = 1; DECLARE @count AS INT = 1; DECLARE @element AS INT = 0; WHILE (@side1 =