Search Results

Search found 1698 results on 68 pages for 'loops'.

Page 12/68 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Need to convert this for loop to a while loop

    - by Bragaadeesh
    Hi guys, I solved a problem recently. But I have this one piece of code where I dont utilize the for loop initialization and condition check. It looks a bit odd that way for a for loop. I want to convert it into a while loop. Please help me do it. I tried many times, but somewhere something is missing. for(;;current =(current+1)%n){ if(eliminated[current%n]){ continue; }else{ inkiPinki++; if(inkiPinki == m){ eliminated[current%n] = true; printStatus(eliminated, people); remainingGuys--; break; } } } In the above code eliminiated[index] is a boolean.

    Read the article

  • Looping through recordset with VBA

    - by Robert
    I am trying to assign salespeople (rsSalespeople) to customers (rsCustomers) in a round-robin fashion in the following manner: Navigate to first Customer, assign the first SalesPerson to the Customer. Move to Next Customer. If rsSalesPersons is not at EOF, move to Next SalesPerson; if rsSalesPersons is at EOF, MoveFirst to loop back to the first SalesPerson. Assign this (current) SalesPerson to the (current) Customer. Repeat step 2 until rsCustomers is at EOF (EOF = True, i.e. End-Of-Recordset). It's been awhile since I dealt with VBA, so I'm a bit rusty, but here is what I have come up with, so far: Private Sub Command31_Click() 'On Error GoTo ErrHandler Dim intCustomer As Integer Dim intSalesperson As Integer Dim rsCustomers As DAO.Recordset Dim rsSalespeople As DAO.Recordset Dim strSQL As String strSQL = "SELECT CustomerID, SalespersonID FROM Customers WHERE SalespersonID Is Null" Set rsCustomers = CurrentDb.OpenRecordset(strSQL) strSQL = "SELECT SalespersonID FROM Salespeople" Set rsSalespeople = CurrentDb.OpenRecordset(strSQL) rsCustomers.MoveFirst rsSalespeople.MoveFirst Do While Not rsCustomers.EOF intCustomers = rsCustomers!CustomerID intSalesperson = rsSalespeople!SalespersonID strSQL = "UPDATE Customers SET SalespersonID = " & intSalesperson & " WHERE CustomerID = " & intCustomer DoCmd.RunSQL (strSQL) rsCustomers.MoveNext If Not rsSalespeople.EOF Then rsSalespeople.MoveNext Else rsSalespeople.MoveFirst End If Loop ExitHandler: Set rsCustomers = Nothing Set rsSalespeople = Nothing Exit Sub ErrHandler: MsgBox (Err.Description) Resume ExitHandler End Sub My tables are defined like so: Customers --CustomerID --Name --SalespersonID Salespeople --SalespersonID --Name With ten customers and 5 salespeople, my intended result would like like: CustomerID--Name--SalespersonID 1---A---1 2---B---2 3---C---3 4---D---4 5---E---5 6---F---1 7---G---2 8---H---3 9---I---4 10---J---5 The above code works for the intitial loop through the Salespeople recordset, but errors out when the end of the recordset is found. Regardless of the EOF, it appears it still tries to execute the rsSalespeople.MoveFirst command. Am I not checking for the rsSalespeople.EOF properly? Any ideas to get this code to work?

    Read the article

  • javascript to reference input IDs in php loop and pass values back to same input ID

    - by Smudger
    I have a form which is essentially an autocomplete input box. I can get this to work perfectly for a single text box. What I need to do is create unique input boxes by using a php for loop. This will use the counter $i to give each input box a unique name and id. The problem is that the unique value of the input box needs to be passed to the javascript. this will then pass the inputted data to the external php page and return the mysql results. As mentioned I have this working for a single input box but need assistance with passing the correct values to the javascript and returning it to correct input box. existing code for working solution (first row works only, all other rows update first row input box) <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("autocompleteperson.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } </script> </head> <body> <form name="form1" id="form1" action="addepartment.php" method="post"> <table> <? for ( $i = 1; $i <=10; $i++ ) { ?> <tr> <td> <? echo $i; ?></td> <td> <div> <input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" /> </div> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="upArrow.png" style="position: relative; top: -12px; left: 20px;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> &nbsp; </div> </div> </td> </tr> <? } ?> </table> </body> </html> code for autocompleteperson.php is: $query = $db->query("SELECT fullname FROM Persons WHERE fullname LIKE '$queryString%' LIMIT 10"); if($query) { while ($result = $query ->fetch_object()) { echo '<li onClick="fill(\''.$result->fullname.'\');">'.$result->fullname.'</li>'; } } in order to get it to work for all rows, I include the counter $i in each of the file names as below: <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> function lookup(inputString<? echo $i; ?>) { if(inputString<? echo $i; ?>.length == 0) { // Hide the suggestion box. $('#suggestions<? echo $i; ?>').hide(); } else { $.post("autocompleteperson.php", {queryString: ""+inputString<? echo $i; ?>+""}, function(data){ if(data.length >0) { $('#suggestions<? echo $i; ?>').show(); $('#autoSuggestionsList<? echo $i; ?>').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString<? echo $i; ?>').val(thisValue); setTimeout("$('#suggestions<? echo $i; ?>').hide();", 200); } </script> </head> <body> <form name="form1" id="form1" action="addepartment.php" method="post"> <table> <? for ( $i = 1; $i <=10; $i++ ) { ?> <tr> <td> <? echo $i; ?></td> <td> <div> <input type="text" size="30" value="" id="inputString<? echo $i; ?>" onkeyup="lookup(this.value);" onblur="fill();" /> </div> <div class="suggestionsBox" id="suggestions<? echo $i; ?>" style="display: none;"> <img src="upArrow.png" style="position: relative; top: -12px; left: 20px;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList<? echo $i; ?>"> &nbsp; </div> </div> </td> </tr> <? } ?> </table> </body> </html> The autocomplete suggestion works (although always shown on first row) but when selecting the data always returns to row 1, even if input was on row 5. I have a feeling this has to do with the fill() but not sure? is it due the the autocomplete page code? or does the fill referencing ThisValue have something to do with it. example of this page (as above) can be found here Thanks for the assistance, much appreciated. UPDATE - LOLO <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> function lookup(i, inputString) { if(inputValue.length == 0) { // Hide the suggestion box. $('#suggestions' + i).hide(); } else { $.post("autocompleteperson.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions' + i).show(); $('#autoSuggestionsList' + i).html(data); } }); } } // lookup function fill(i, thisValue) { $('#inputString' + i).val(thisValue); setTimeout("$('#suggestions' + i).hide();", 200); } </script> </head> <body> <form name="form1" id="form1" action="addepartment.php" method="post"> <table> <? for ( $i = 1; $i <=10; $i++ ) { ?> <tr> <td> <? echo $i; ?></td> <td> <div> <input type="text" size="30" value="" id="inputString<?php echo $i; ?>" onkeyup="lookup(this.value);" onblur="fill();" /> </div> <div class="suggestionsBox" id="suggestions<? echo $i; ?>" style="display: none;"> <img src="upArrow.png" style="position: relative; top: -12px; left: 20px;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList<? echo $i; ?>"> &nbsp; </div> </div> </td> </tr> <? } ?> </table> </body> </html> google chrome catched the following errors: first line on input, second line on loosing focus

    Read the article

  • Ruby: How to loop through an object that may or may not be an array?

    - by Shpigford
    I have an each method that is run on some user-submitted data. Sometimes it will be an array, other times it won't be. Example submission: <numbers> <number>12345</number> </numbers> Another example: <numbers> <number>12345</number> <number>09876</number> </numbers> I have been trying to do an each do on that, but when there is only one number I get a TypeError (Symbol as array index) error.

    Read the article

  • Run a PHP script every second using CLI

    - by Saif Bechan
    Hello, I have a dedicated server running Cent OS with a Parallel PLESK panel. I need to run a php script every second, that updates my database. These is no alternative way timewise, i have checked every method, it needs to be updated every second. I can find my script using the url: http://www.mysite.com/phpfile.php?key=123, and this has to be executed every second. Does anyone have any knowledge at all on doing this, i can not seem to find the answer. I heard about doing it with CLI and putty, but i have no knowledge of this at all. Or can this be done using the PLESK Panel? And can the file be executed locally every second. Like \phpfile.php If someone helps me on answering these question i would really appreciate it. Regards EDIT It has been a few months since i added this question. I ended up using the following code: #!/user/bin/php $start = microtime(true); set_time_limit(60); for (i = 0; i < 59; ++$i) { doMyThings(); time_sleep_until($start + $i + 1); } Thank you for this code guys! My cronjob is set to every minute. I have been running this for some time now in a test environment, and this works out great. It works really supperfast, and i see no increase in CPU nor Memory usage.

    Read the article

  • How can I return default at loop end in Scheme?

    - by Kufi Annan
    I'm trying to implement back-tracking search in Scheme. So far, I have the following: (define (backtrack n graph assignment) (cond (assignment-complete n assignment) (assignment) ) (define u (select-u graph assignment)) (define c 1) (define result 0) (let forLoop () (when (valid-choice graph assignment c) (hash-set! assignment u c) (set! result (backtrack n graph assignment)) (cond ((not (eq? result #f)) result)) (hash-remove! assignment u) ) (set! c (+ c 1)) (when (>= n c) (forLoop)) ) #f ) My functions assignment-complete and select-u pass unit tests. The argument assignment is a hash-table make with (make-hash), so it should be fine. I believe the problem I have is related to returning false at the end of the loop, if no recursive returns a non-false value (which should be a valid assignment).

    Read the article

  • algorithm to find overlaps

    - by Gary
    Hey, Basically I've got some structs of type Ship which are going to go on a board which can have a variable width and height. The information about the ships is read in from a file, and I just need to know the best way to make sure that none of the ships overlap. Here is the structure of Ship: int x // x position of first part of ship int y // y position of first part of ship char dir // direction of the ship, either 'N','S','E' or 'W' int length // length of the ship Also, what would be a good way to handle the directions. Something cleaner than using a switch statement and using a different condition for each direction. Any help would be greatly appreciated!

    Read the article

  • Iterating backward

    - by MBennett
    Suppose I have a vector<int> myvec and I want to loop through all of the elements in reverse. I can think of a few ways of doing this: for (vector<int>::iterator it = myvec.end() - 1; it >= myvec.begin(); --it) { // do stuff here } for (vector<int>::reverse_iterator rit = myvec.rbegin(); rit != myvec.rend(); ++rit) { // do stuff here } for (int i = myvec.size() - 1; i >= 0; --i) { // do stuff here } So my question is when should I use each? Is there a difference? I know that the first one is dangerous because if I pass in an empty vector, then myvec.end() - 1 is undefined, but are there any other hazards or inefficiencies with this?

    Read the article

  • Why does this break statement break not work?

    - by Roman
    I have the following code: public void post(String message) { final String mess = message; (new Thread() { public void run() { while (true) { try { if (status.equals("serviceResolved")) { output.println(mess); Game.log.fine("The following message was successfully sent: " + mess); break; } else { try {Thread.sleep(1000);} catch (InterruptedException ie) {} } } catch (NullPointerException e) { try {Thread.sleep(1000);} catch (InterruptedException ie) {} } } } }).start(); } In my log file I find a lot of lines like this: The following message was successfully sent: blablabla The following message was successfully sent: blablabla The following message was successfully sent: blablabla The following message was successfully sent: blablabla And my program is not responding. It seems to me that the break command does not work. What can be a possible reason for that. The interesting thing is that it happens not all the time. Sometimes my program works fine, sometimes the above described problem happens.

    Read the article

  • Foreach loop is running n times

    - by Furqan Khyraj
    foreach($CarAdList as $CarAd) { echo($msg .= '<tr><td>'.$CarAd->getCarAdID().'</td><td>' .$CarAd->getBrandText().'</td><td>' .$CarAd->getDescription(). '</td><td><a href="status.php?id='.$CarAd->getCarAdID().'"><img src="../images/active.png" /></a></td><td><img src="../images/delete.png" width="30px" /></td></tr>'); } e.g, the number of rows =38 n= the number of rows * the number of rows-- it is running n times so its displaying 5 5 4 5 4 3 5 4 3 2 5 4 3 2 1

    Read the article

  • Insert Data from to a table

    - by Lee_McIntosh
    I have a table that lists number of comments from a particular site like the following: Date Site Comments Total --------------------------------------------------------------- 2010-04-01 00:00:00.000 1 5 5 2010-04-01 00:00:00.000 2 8 13 2010-04-01 00:00:00.000 4 2 7 2010-04-01 00:00:00.000 7 13 13 2010-04-01 00:00:00.000 9 1 2 I have another table that lists ALL sites for example from 1 to 10 Site ----- 1 2 ... 9 10 Using the following code i can find out which sites are missing entries for the previous month: SELECT s.site from tbl_Sites s EXCEPT SELECT c.site from tbl_Comments c WHERE c.[Date] = DATEADD(mm, DATEDIFF(mm, 0, GetDate()) -1,0) Producing: site ----- 3 5 6 8 10 I would like to be able to insert the missing sites that is listed from my query into the comments table with some default values, i.e '0's Date Site Comments Total --------------------------------------------------------------- 2010-04-01 00:00:00.000 3 0 0 2010-04-01 00:00:00.000 5 0 0 2010-04-01 00:00:00.000 6 0 0 2010-04-01 00:00:00.000 8 0 0 2010-04-01 00:00:00.000 10 0 0 the question is, how did i update/insert the table/values? cheers, Lee

    Read the article

  • Program contains 2 nested loops which contain 4 if conditionals. How many paths?

    - by Student4Life
    In Roger Pressman's book, there is an example described of a program with 2 nested loops, the inner loop enclosing four if statements. The two loops can execute up to 20 times. He states that this makes about 10^14 paths. To get a number this large, it seems the paths inside the loops are multipllied by 2^40, i.e. 2^20 times 2^20 to account for all the possibilities of going through the two loops. I can't see why this factor is not just 400, i.e. 20 times 20. Can someone shed some light? It will help if you have the ppt slides and can see the program graph. Thanks.

    Read the article

  • iPhone game reading plist file and looping through multi dimensional array.

    - by Fulvio
    I have a question regarding an iPhone game I'm developing. At the moment, below is the code I'm using to currently I loop through my multidimensional array and position bricks accordingly on my scene. Instead of having multiple two dimensional arrays within my code as per the following (gameLevel1). Ideally, I'd like to read from a .plist file within my project and loop through the values in that instead. Please take into account that I'd like to have more than one level within my game (possibly 20) so my .plist file would have to have some sort of separator line item to determine what level I want to render. I was then thinking of having some sort of method that I call and that method would take the level number I'm interested in rendering. e.g. Method? +(void)renderLevel:(NSString levelNumber); e.g. .plist file? #LEVEL_ONE# 0,0,0,0,0,0,0,0,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,1,1,1,1,1,1,1,0 0,0,0,0,0,0,0,0,0 #LEVEL_TWO# 1,0,0,0,0,0,0,0,1 1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1 0,1,1,1,1,1,1,1,0 1,1,1,1,1,1,1,1,1 0,1,1,1,1,1,1,1,0 1,1,1,1,1,1,1,1,1 0,1,1,1,1,1,1,1,0 1,1,1,1,1,1,1,1,1 0,1,1,1,1,1,1,1,0 1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1 1,0,0,0,0,0,0,0,1 Code that I'm currently using: int gameLevel[17][9] = { { 0,0,0,0,0,0,0,0,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,1,1,1,1,1,1,1,0 }, { 0,0,0,0,0,0,0,0,0 } }; for (int row=0; row < 17; row++) { for (int col=0; col < 9; col++) { thisBrickValue = gameLevel[row][col]; xOffset = 35 * floor(col); yOffset = 22 * floor(row); switch (thisBrickValue) { case 0: brick = [[CCSprite spriteWithFile:@"block0.png"] autorelease]; break; case 1: brick = [[CCSprite spriteWithFile:@"block1.png"] autorelease]; break; } brick.position = ccp(xOffset, yOffset); [self addChild:brick]; } }

    Read the article

  • Trying to sentinel loop this program.

    - by roger34
    Okay, I spent all this time making this for class but I have one thing that I can't quite get: I need this to sentinel loop continuously (exiting upon entering x) so that the System.out.println("What type of Employee? Enter 'o' for Office " + "Clerical, 'f' for Factory, or 's' for Saleperson. Enter 'x' to exit." ); line comes back up after they enter the first round of information. Also, I can't leave this up long on the (very) off chance a classmate might see this and steal the code. Full code following: import java.util.Scanner; public class Project1 { public static void main (String args[]){ Scanner inp = new Scanner( System.in ); double totalPay; System.out.println("What type of Employee? Enter 'o' for Office " + "Clerical, 'f' for Factory, or 's' for Saleperson. Enter 'x' to exit." ); String response= inp.nextLine(); while (!response.toLowerCase().equals("o")&&!response.toLowerCase().equals("f") &&!response.toLowerCase().equals("s")&&!response.toLowerCase().equals("x")){ System.out.print("\nInvalid selection,please enter your choice again:\n"); response=inp.nextLine(); } char choice = response.toLowerCase().charAt( 0 ); switch (choice){ case 'o': System.out.println("Enter your hourly rate:"); double officeRate=inp.nextDouble(); System.out.println("Enter the number of hours worked:"); double officeHours=inp.nextDouble(); totalPay = officeCalc(officeRate,officeHours); taxCalc(totalPay); break; case 'f': System.out.println("How many Widgets did you produce during the week?"); double widgets=inp.nextDouble(); totalPay=factoryCalc(widgets); taxCalc(totalPay); break; case 's': System.out.println("What were your total sales for the week?"); double totalSales=inp.nextDouble(); totalPay=salesCalc(totalSales); taxCalc(totalPay); break; } } public static double taxCalc(double totalPay){ double federal=totalPay*.22; double state =totalPay*.055; double netPay = totalPay - federal - state; federal =federal*Math.pow(10,2); federal =Math.round(federal); federal= federal/Math.pow(10,2); state =state*Math.pow(10,2); state =Math.round(state); state= state/Math.pow(10,2); totalPay =totalPay*Math.pow(10,2); totalPay =Math.round(totalPay); totalPay= totalPay/Math.pow(10,2); netPay =netPay*Math.pow(10,2); netPay =Math.round(netPay); netPay= netPay/Math.pow(10,2); System.out.printf("\nTotal Pay \t: %1$.2f.\n", totalPay); System.out.printf("State W/H \t: %1$.2f.\n", state); System.out.printf("Federal W/H : %1$.2f.\n", federal); System.out.printf("Net Pay \t: %1$.2f.\n", netPay); return totalPay; } public static double officeCalc(double officeRate,double officeHours){ double overtime=0; if (officeHours>=40) overtime = officeHours-40; else overtime = 0; if (officeHours >= 40) officeHours = 40; double otRate = officeRate * 1.5; double totalPay= (officeRate * officeHours) + (otRate*overtime); return totalPay; } public static double factoryCalc(double widgets){ double totalPay=widgets*.35 +300; return totalPay; } public static double salesCalc(double totalSales){ double totalPay = totalSales * .05 + 500; return totalPay; } }

    Read the article

  • random, Graphics point ,searching- algorithm, via dual for loop set

    - by LoneXcoder
    hello and thanks for joining me in my journey to the custom made algorithm for "guess where the pixel is" this for Loop set (over Point.X, Point.Y), is formed in consecutive/linear form: //Original\initial Location Point initPoint = new Point(150, 100); // No' of pixels to search left off X , and above Y int preXsrchDepth, preYsrchDepth; // No' of pixels to search to the right of X, And Above Y int postXsrchDepth, postYsrchDepth; preXsrchDepth = 10; // will start search at 10 pixels to the left from original X preYsrchDepth = 10; // will start search at 10 pixels above the original Y postXsrchDepth = 10; // will stop search at 10 pixels to the right from X postYsrchDepth = 10; // will stop search at 10 pixels below Y int StopXsearch = initPoint.X + postXsrchDepth; //stops X Loop itarations at initial pointX + depth requested to serch right of it int StopYsearch = initPoint.Y + postYsrchDepth; //stops Y Loop itarations at initial pointY + depth requested below original location int CountDownX, CountDownY; // Optional not requierd for loop but will reports the count down how many iterations left (unless break; triggerd ..uppon success) Point SearchFromPoint = Point.Empty; //the point will be used for (int StartX = initPoint.X - preXsrchDepth; StartX < StopXsearch; StartX++) { SearchFromPoint.X = StartX; for (int StartY = initPoint.Y - preYsrchDepth; StartY < StpY; StartY++) { CountDownX = (initPoint.X - StartX); CountDownY=(initPoint.Y - StartY); SearchFromPoint.Y = StartY; if (SearchSuccess) { same = true; AAdToAppLog("Search Report For: " + imgName + "Search Completed Successfully On Try " + CountDownX + ":" + CountDownY); break; } } } <-10 ---- -5--- -1 X +1--- +5---- +10 what i would like to do is try a way of instead is have a little more clever approach <+8---+5-- -8 -5 -- +2 +10 X -2 - -10 -8-- -6 ---1- -3 | +8 | -10 Y +1 -6 | | +9 .... I do know there's a wheel already invented in this field (even a full-trailer truck amount of wheels (: ) but as a new programmer, I really wanted to start of with a simple way and also related to my field of interest in my project. can anybody show an idea of his, he learnt along the way to Professionalism in algorithm /programming having tests to do on few approaches (kind'a random cleverness...) will absolutely make the day and perhaps help some others viewing this page in the future to come it will be much easier for me to understand if you could use as much as possible similar naming to variables i used or implenet your code example ...it will be Greatly appreciated if used with my code sample, unless my metod is a realy flavorless. p.s i think that(atleast as human being) the tricky part is when throwing inconsecutive numbers you loose track of what you didn't yet use, how do u take care of this too . thanks allot in advance looking forward to your participation !

    Read the article

  • How to organize infinite while loop in SQL Server ?

    - by alpav
    I want to use infinite WHILE loop in SQL Server 2005 and use BREAK keyword to exit from it on certain condition. while true does not work, so I have to use while 1=1. Is there a better way to organize infinite loop ? I know that I can use goto, but while 1=1 begin .. end looks better structurally.

    Read the article

  • java looping - declaration of a Class outside / inside the loop

    - by lisak
    when looping, for instance: for ( int j = 0; j < 1000; j++) {}; and I need to instantiate 1000 objects, how does it differ when I declare the object inside the loop from declaring it outside the loop ?? for ( int j = 0; j < 1000; j++) {Object obj; obj =} vs Object obj; for ( int j = 0; j < 1000; j++) {obj =} It's obvious that the object is accessible either only from the loop scope or from the scope that is surrounding it. But I don't understand the performance question, garbage collection etc. What is the best practice ? Thank you

    Read the article

  • Deleting duplicates in Delphi listview

    - by radick
    I am trying to remove duplicates in my listview. This function: procedure RemoveDuplicates(const LV:TbsSkinListView); var i,j: Integer; begin LV.Items.BeginUpdate; LV.SortType := stText; try for i := 0 to LV.Items.Count-1 do begin for j:=i+1 to LV.Items.Count-1 do begin if SameText(LV.Items[i].SubItems[0], LV.Items[j].SubItems[0]) and SameText(LV.Items[i].SubItems[1], LV.Items[j].SubItems[1]) and SameText(LV.Items[i].SubItems[2], LV.Items[j].SubItems[2]) and SameText(LV.Items[i].SubItems[3], LV.Items[j].SubItems[3]) then LV.Items.Delete(j); end; end; finally LV.SortType := stNone; LV.Items.EndUpdate; end; ShowMessage('Deleted'); end; does not delete the duplicates. What is wrong with it?

    Read the article

  • How can I return a sql select into a sql variable

    - by Matt
    Hi, I'm trying to put the results of a SELECT into a variable and loop through the results to manipulate that data, all in the same stored proceedure... Here's what I have so far: DECLARE @i int @Result = (SELECT * FROM UserImport) SET @i = 0 WHILE @i < (SELECT Count(@Result) As Count) BEGIN /* Do Stuff */ END I know I'm way off because it's saying @Result was not declared, but I'm not sure how to declare a variable to be able to hold the results of a SELECT statement. Can anyone tell me where i'm going wrong and how to fix it? Thanks, Matt

    Read the article

  • Loop append div and repeat

    - by Diego Vieira
    I have this code <div class="round-3-top"> <div class="round-2-top"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> <div class="round-2-bottom"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> </div> <div class="round-3-bottom"> <div class="round-2-top"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> <div class="round-2-bottom"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> </div> But i want generate dynamically, how i do that? Ex.: i have 4 rounds, this would be the generated code <div class="round-4-top"> <div class="round-3-top"> <div class="round-2-top"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> <div class="round-2-bottom"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> </div> <div class="round-3-bottom"> <div class="round-2-top"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> <div class="round-2-bottom"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> </div> </div> <div class="round-4-bottom"> <div class="round-3-top"> <div class="round-2-top"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> <div class="round-2-bottom"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> </div> <div class="round-3-bottom"> <div class="round-2-top"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> <div class="round-2-bottom"> <div class="round-1-top"></div> <div class="round-1-bottom"></div> </div> </div> </div> I try using TagBuilder in MVC C# but I can not do. What should happen is, if you are 3 rounds, adding he should go inside each div is like the example above. Any idea how can I develop it?

    Read the article

  • PHP & cUrl - POST problems in while loop.

    - by Max Hoff
    I have a while loop, with cUrl inside. (I can't use curl_multi for various reasons.) The problem is that cUrl seems to save the data it POSTS after each loop traversal. For instance, if parameter X is One the first loop through, and if it's Two the second loop through, cUrl posts: "One,Two". It should just POST "Two".(This is despite closing and unsetting the curl handle.) Here's a simplified version of the code (with unecessary info stripped out): while(true){ // code to form the $url. this code is local to the loop. so the variables should be "erased" and made new for each loop through. $ch = curl_init(); $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; curl_setopt($ch,CURLOPT_USERAGENT, $userAgent); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $html = curl_exec($ch); curl_close($ch); unset($ch); $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $resultTable = $xpath->evaluate("/html/body//table"); // $resultTable is 20 the first time through the loop, and 0 everytime thereafter becauset he POSTing doesn't work right with the "saved" parameters. What am I doing wrong here?

    Read the article

  • jwplayer embedded with recent flash with html5 back end cant hide controls or add autoplay and loop

    - by Daniel Redwood
    Hey all, After the unfortunate realization that Firefox is just not going to play nice with an embedded HTML5 video with my server set up, I've decided to go the JW Player route, since it's compatible with iPads and iPhones. I can get the file to show up on my page, but it's big and heavy. I would like for it to be just the video, no controls. Autoplay and on loop. Can you help me out? Here's the code... <div id="container">Loading the player ...</div> jwplayer("container").setup({ flashplayer: "jwplayer/player.swf", file: "Video/fernando.m4v", height: 520, width: 780, }); <script type='text/javascript' src='swfobject.js'></script>

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >