Search Results

Search found 8557 results on 343 pages for 'infinite loop'.

Page 14/343 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • How to break a loop when inputting unspecified raw_input?

    - by user1874510
    I want to write an interface using a while loop and raw_input. My code looks like this: while True: n = raw_input("'p' = pause, 'u' = unpause, 'p' = play 's' = stop, 'q' = quit) if n.strip() == 'p': mp3.pause() if n.strip() == 'u': mp3.unpause() if n.strip() == 'p': mp3.play() if n.strip() == 's': mp3.stop() if n.strip() == 'q': break But I want it to break if I input anything that isn't specified in the raw_input. if not raw_input: break Returns and IndentationError: unindent does not match any outer indentation level. if not raw_input: break Does not return any error but doesn't work as I want it to. As far as I know, it does nothing at all. Also, if there's a cleaner way to write my loop, I love to hear it.

    Read the article

  • PHP: How do I loop through every XML file in a directory?

    - by celebritarian
    Hi! I'm building a simple application. It's a user interface to an online order system. Basically, the system is going to work like this: Other companies upload their purchase orders to our FTP server. These orders are simple XML files (containing things like customer data, address information, ordered products and the quantities…) I've built a simple user interface in HTML5, jQuery and CSS — all powered by PHP. PHP reads the content of an order (using the built-in features of SimpleXML) and displays it on the web page. So, it's a web app, supposed to always be running in a browser at the office. The PHP app will display the content of all orders. Every fifteen minutes or so, the app will check for new orders. How do I loop through all XML files in a directory? Right now, my app is able to read the content of a single XML file, and display it in a nice way on the page. My current code looks like this: // pick a random order that I know exists in the Order directory: $xml_file = file_get_contents("Order/6366246.xml",FILE_TEXT); $xml = new SimpleXMLElement($xml_file); // start echo basic order information, like order number: echo $xml->OrderHead->ShopPO; // more information about the order and the customer goes here… echo "<ul>"; // loop through each order line, and echo all quantities and products: foreach ($xml->OrderLines->OrderLine as $orderline) { echo "<tr>\n". "<li>".$orderline->Quantity." st.</li>\n". "<li>".$orderline->SKU."</li>\n"; } echo "</ul>"; // more information about delivery options, address information etc. goes here… So, that's my code. Pretty simple. It only needs to do one thing — print out the content of all order files on the screen — so me and my colleagues can see the order, confirm it and deliver it. That's it. But right now — as you can see — I'm selecting one single order at a time, located in the Order directory. But how do I loop through the entire Order directory, and read aand display the content of each order (like above)? I'm stuck. I don't really know how you get all (xml) files in a directory and then do something with the files (like reading them and echo out the data, like I want to). -- I'd really appreciate some help. I'm not very experienced with PHP/server-side programming, so if you could help me out here I'd be very grateful. Thanks a lot in advance! // Björn (celebritarian at me dot com)

    Read the article

  • how to do event checks for loops?

    - by yao jiang
    I am having some trouble getting the logic down for this. Currently, I have an app that animates the astar pathfinding algorithm. On start of the app, the ui will show the following: User can press "space" to randomly choose start/end coords, then the app will animate it. Or, user can choose the start/end by left-click/right-click. During the animation, the user can also left-click to generate blocks, or right-click to choose a new destiantion. Where I am stuck at is how to handle the events while the app is animating. Right now, I am checking events in the main loop, then when the app is animating, I do event checks again. While it works fine, I feel that I am probably doing it wrong. What is the proper way of setting up the main loop that will handle the events while the app is animating? In main loop, the app start animating once user choose start/end. In my draw function, I am putting another event checker in there. def clear(rows): for r in range(rows): for c in range(rows): if r%3 == 1 and c%3 == 1: color = brown; grid[r][c] = 1; buildCoor.append(r); buildCoor.append(c); else: color = white; grid[r][c] = 0; pick_image(screen, color, width*c, height*r); pygame.display.flip(); os.system('cls'); # draw out the grid def draw(start, end, grid, route_coord): # draw the end coords color = red; pick_image(screen, color, width*end[1],height*end[0]); pygame.display.flip(); # then draw the rest of the route for i in range(len(route_coord)): # pausing because we want animation time.sleep(speed); # get the x/y coords x,y = route_coord[i]; event_on = False; if grid[x][y] == 2: color = green; elif grid[x][y] == 3: color = blue; for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 3: print "destination change detected, rerouting"; # get mouse position, px coords pos = pygame.mouse.get_pos(); # get grid coord c = pos[0] // width; r = pos[1] // height; grid[r][c] = 4; end = [r, c]; elif event.button == 1: print "user generated event"; pos = pygame.mouse.get_pos(); # get grid coord c = pos[0] // width; r = pos[1] // height; # mark it as a block for now grid[r][c] = 1; event_on = True; if check_events([x,y]) or event_on: # there is an event # mark it as a block for now grid[y][x] = 1; pick_image(screen, event_x, width*y, height*x); pygame.display.flip(); # then find a new route new_start = route_coord[i-1]; marked_grid, route_coord = find_route(new_start, end, grid); draw(new_start, end, grid, route_coord); return; # just end draw here so it wont throw the "index out of range" error elif grid[x][y] == 4: color = red; pick_image(screen, color, width*y, height*x); pygame.display.flip(); # clear route coord list, otherwise itll just add more unwanted coords route_coord_list[:] = []; clear(rows); # main loop while not done: # check the events for event in pygame.event.get(): # mouse events if event.type == pygame.MOUSEBUTTONDOWN: # get mouse position, px coords pos = pygame.mouse.get_pos(); # get grid coord c = pos[0] // width; r = pos[1] // height; # find which button pressed, highlight grid accordingly if event.button == 1: # left click, start coords if grid[r][c] == 2: grid[r][c] = 0; color = white; elif grid[r][c] == 0 or grid[r][c] == 4: grid[r][c] = 2; start = [r,c]; color = green; else: grid[r][c] = 1; color = brown; elif event.button == 3: # right click, end coords if grid[r][c] == 4: grid[r][c] = 0; color = white; elif grid[r][c] == 0 or grid[r][c] == 2: grid[r][c] = 4; end = [r,c]; color = red; else: grid[r][c] = 1; color = brown; pick_image(screen, color, width*c, height*r); # keyboard events elif event.type == pygame.KEYDOWN: clear(rows); # one way to quit program if event.key == pygame.K_ESCAPE: print "program will now exit."; done = True; # space key for random start/end elif event.key == pygame.K_SPACE: # first clear the ui clear(rows); # now choose random start/end coords buildLoc = zip(buildCoor,buildCoor[1:])[::2]; #print buildLoc; (start_x, start_y, end_x, end_y) = pick_point(); while (start_x, start_y) in buildLoc or (end_x, end_y) in buildLoc: (start_x, start_y, end_x, end_y) = pick_point(); clear(rows); print "chosen random start/end coords: ", (start_x, start_y, end_x, end_y); if (start_x, start_y) in buildLoc or (end_x, end_y) in buildLoc: print "error"; # draw the route marked_grid, route_coord = find_route([start_x,start_y],[end_x,end_y], grid); draw([start_x, start_y], [end_x, end_y], marked_grid, route_coord); # return key for user defined start/end elif event.key == pygame.K_RETURN: # first clear the ui clear(rows); # get the user defined start/end print "user defined start/end are: ", (start[0], start[1], end[0], end[1]); grid[start[0]][start[1]] = 1; grid[end[0]][end[1]] = 2; # draw the route marked_grid, route_coord = find_route(start, end, grid); draw(start, end, marked_grid, route_coord); # c to clear the screen elif event.key == pygame.K_c: print "clearing screen."; clear(rows); # go fullscreen elif event.key == pygame.K_f: if not full_sc: pygame.display.set_mode([1366, 768], pygame.FULLSCREEN); full_sc = True; rows = 15; clear(rows); else: pygame.display.set_mode(size); full_sc = False; # +/- key to change speed of animation elif event.key == pygame.K_LEFTBRACKET: if speed >= 0.1: print SPEED_UP; speed = speed_up(speed); print speed; else: print FASTEST; print speed; elif event.key == pygame.K_RIGHTBRACKET: if speed < 1.0: print SPEED_DOWN; speed = slow_down(speed); print speed; else: print SLOWEST print speed; # second method to quit program elif event.type == pygame.QUIT: print "program will now exit."; done = True; # limit to 20 fps clock.tick(20); # update the screen pygame.display.flip();

    Read the article

  • Nginx infinite redirect loop

    - by Zachary Burt
    Why is http://compassionpit.com/blog/ going through an infinite redirect loop? Here's my nginx conf file. The site is run by a nodejs server on port 8000 and Apache serves up the blog (wordpress) and the forum (phpBB). The forum is resolving just fine, at http://www.compassionpit.com/forum/ ... server { listen 80; server_name www.compassionpit.org; rewrite ^/(.*) http://www.compassionpit.com/$1 permanent; } server { listen 80; # your server's public IP address server_name www.compassionpit.com; index index.php index.html; location ~ ^/$ { proxy_pass http://127.0.0.1:8000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location @blogphp { internal; root /opt/blog/; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/index.php; fastcgi_index index.php; fastcgi_pass 127.0.0.1:8080; } location ~ ^/(forum|blog)/($|.*\.php) { root /opt/; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; fastcgi_pass 127.0.0.1:8080; } location ~ ^/(forum|blog) { root /opt/; try_files $uri $uri/ @blogphp; } location ~ ^/(forum|blog)/ { root /opt/; } location @backend { internal; proxy_pass http://127.0.0.1:8000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~ / { root /opt/chat/static/; try_files $uri $uri/ @backend; } }

    Read the article

  • Cacti Login Page: Infinite loop occurs

    - by beicha
    Apache 2.2.3 | PHP 5.1.6 | MySQL 5.0.77 I followed cacti installation guide to install latest cacti 0.8.7h on CentOS 5.5 (64-bit). The installation of PHP/Apache/MySQL went smoothly until I finished the setup, and came to the login page. I can login http://.../cacti/index.php with admin account but the new page is redirected to the same login page with the message "Please enter your Cacti user name and password below" This is a infinite loop! If I use a wrong admin password I get the correct error message "Invalid User Name/Password Please Retype". [Same problem here] If I login use Guest/guest account, "Error: Access Denied, user account disabled." displays. The Cacti log file (./cacti/log/cacti.log) is empty. I Googled and seems this problem has existed for a long time, but no followup solutions were found on the forum posts I found. Anyone can help me on this problem? If more information needed, please let me know. Nov 18, 2011 UPDATE: I re-installed Cacti, this question remains UNSOLVED.

    Read the article

  • Any way to loop through FPDF code with proper XY coordinates?

    - by JM4
    At the end of a form collection, I provide the consumer a printable PDF with the information they just entered. I already run through a loop to store the variables themselves but am wondering if it is at all possible to build a loop that builds on itself for FPDF. The catch is this, each new variable (#1, #2, #3) will change location by a determined amount of space. For example: I print the Member #1 First name at coordinate at coordinate (95, 101). I print Member #2 First name at coordinate (95, 110)... and so on. Each known variable will be 9.5mm greater than its previous entry (therefor Member #9 will be 40mm higher than Member 6) My sample code for the FPDF itself is: $pdf->SetFont('Arial','', 7); $pdf->SetXY(8,76.5); $pdf->Cell(20,0,$f1name); $pdf->SetFont('Arial','', 5); $pdf->SetXY(50.5,76.5); $pdf->Cell(20,0,$f1address); $pdf->SetFont('Arial','', 7); $pdf->SetXY(95.7,76.5); $pdf->Cell(20,0,$f1city); $pdf->SetXY(129.5,76.5); $pdf->Cell(20,0,$f1state); $pdf->SetXY(139.1,76.5); $pdf->Cell(20,0,$f1zip); $pdf->SetXY(151,76.5); $pdf->Cell(20,0,$f1dob); $pdf->SetXY(168,76.5); $pdf->Cell(20,0,$f1ssn); $pdf->SetXY(186,76.5); $pdf->Cell(20,0,$f1phone); $pdf->SetXY(55,81.1); $pdf->Cell(20,0,$f1email); $pdf->SetXY(129,81.1); $pdf->Cell(20,0,$f1fednum); Ideally, all Y variables with $f2 would be 9.5mm greater than f1's Y values.

    Read the article

  • how to do loop for array which have different data for each array

    - by Suriani Salleh
    i have this file XML file.. I need to convert it form XMl to MYSQL. if it have only one array than i know how to do it.. now my question how to extract this two array Each array will have different value of data..for example for first array, pmIntervalTxEthMaxUtilization data : 0,74,0,0,48 and for second array pmIntervalRxPowerLevel data: -79,-68,-52 , pmIntervalTxPowerLevel data: 13,11,-55 . can some one help to guide how write php code to extract this xml file to MY SQL <mi> <mts>20130618020000</mts> <gp>900</gp> <mt>pmIntervalRxUndersizedFrames</mt> [ this is first array] <mt>pmIntervalRxUnicastFrames</mt> <mt>pmIntervalTxUnicastFrames</mt> <mt>pmIntervalRxEthMaxUtilization</mt> <mt>pmIntervalTxEthMaxUtilization</mt> <mv> <moid>port:1:3:23-24</moid> <sf>FALSE</sf> <r>0</r> [the data for 1st array i want to insert in DB] <r>0</r> <r>0</r> <r>5</r> <r>0</r> </mv> </mi> <mi> <mts>20130618020000</mts> <gp>900</gp> <mt>pmIntervalRxSES</mt> [this is second array] <mt>pmIntervalRxPowerLevel</mt> <mt>pmIntervalTxPowerLevel</mt> <mv> <moid>client:1:3:23-24</moid> <sf>FALSE</sf> <r>0</r> [the data for 2nd array i want to insert in DB] <r>-79</r> <r>13</r> </mv> </mi> this is the code for one array that i write..i dont know how to write code for two array because the field appear two times and have different data value for each array // Loop through the specified xpath foreach($xml->mi->mv as $subchild) { $port_no = $subchild->moid; $rx_ses = $subchild->r[0]; $rx_es = $subchild->r[1]; $tx_power = $subchild->r[10]; // dump into database; ........................... i have do a little research on it this is the out come... $i = 0; while( $i < 5) { // Loop through the specified xpath foreach($xml->md->mi->mv as $subchild) { $port_no = $subchild->moid; $rx_uni = $subchild->r[10]; $tx_uni = $subchild->r[11]; $rx_eth = $subchild->r[16]; $tx_eth = $subchild->r[17]; // dump into database; .............................. $i++; if( $i == 5 )break; } } // Loop through the specified xpath foreach($xml->mi->mv as $subchild) { $port_no = $subchild->moid; $rx_ses = $subchild->r[0]; $rx_es = $subchild->r[1]; $tx_power = $subchild->r[10]; // dump into database; .......................

    Read the article

  • vb.net sqlite how to loop through selected records and pass each record as a parameter to another fu

    - by mazrabul
    Hi, I have a sqlite table with following fields: Langauge level hours German 2 50 French 3 40 English 1 60 German 1 10 English 2 50 English 3 60 German 1 20 French 2 40 I want to loop through the records based on language and other conditions and then pass the current selected record to a different function. So I have the following mixture of actual code and psudo code. I need help with converting the psudo code to actual code, please. I am finding it difficult to do so. Here is what I have: Private sub mainp() Dim oslcConnection As New SQLite.SQLiteConnection Dim oslcCommand As SQLite.SQLiteCommand Dim langs() As String = {"German", "French", "English"} Dim i as Integer = 0 oslcConnection.ConnectionString = "Data Source=" & My.Settings.dbFullPath & ";" oslcConnection.Open() oslcCommand = oslcConnection.CreateCommand Do While i <= langs.count If langs(i) = "German" Then oslcCommand.CommandText = "SELECT * FROM table WHERE language = '" & langs(i) & "';" For each record selected 'psudo code If level = 1 Then 'psudo code update level to 2 'psudo code minorp(currentRecord) 'psudo code: calling minorp function and passing the whole record as a parameter End If 'psudo code If level = 2 Then 'psudo code update level to 3 'psudo code minorp(currentRecord) 'psudo code: calling minorp function and passing the whole record as a parameter End If 'psudo code Next 'psudo code End If If langs(i) = "French" Then oslcCommand.CommandText = "SELECT * FROM table WHERE language = '" & langs(i) & "';" For each record selected 'psudo code If level = 1 Then 'psudo code update level to 2 'psudo code minorp(currentRecord) 'psudo code: calling minorp function and passing the whole record as a parameter End If 'psudo code If level = 2 Then 'psudo code update level to 3 'psudo code minorp(currentRecord) 'psudo code: calling minorp function and passing the whole record as a parameter End If 'psudo code Next 'psudo code End If Loop End Sub Many thanks for your help.

    Read the article

  • How to write PowerShell code part 4 (using loop)

    - by ybbest
    In this post, I’d like to show you how to loop through the xml element. I will use the list data deletion script as an example. You can download the script here. 1. To perform the loop, I use foreach in powershell. Here is my xml looks like <?xml version="1.0" encoding="utf-8"?> <Site Url="http://workflowuat/npdmoc"> <Lists> <List Name="YBBEST Collaboration Areas" Type="Document Library"/> <List Name="YBBEST Project" /> <List Name="YBBEST Document"/> </Lists> </Site> 2. Here is the PowerShell to manipulate the xml. Note, you need to get to the $configurationXml.Site.Lists.List variable rather than $configurationXml.Site.Lists foreach ($list in $configurationXml.Site.Lists.List){ AppendLog "Clearing data for $($list.Name) at site $weburl" Yellow if($list.Type -eq "Document Library"){ deleteItemsFromDocumentLibrary -Url $weburl -ListName $list.Name }else{ deleteItemsFromList -Url $weburl -ListName $list.Name } AppendLog "Data in $($list.Name) at $weburl is cleared" Green } How to write PowerShell code part 1 How to write PowerShell code part 2 How to write PowerShell code part 3 How to write PowerShell code part 4

    Read the article

  • Correct way to drive Main Loop in Cocoa

    - by Kyle
    I'm writing a game that currently runs in both Windows and Mac OS X. My main game loop looks like this: while(running) { ProcessOSMessages(); // Using Peek/Translate message in Win32 // and nextEventMatchingMask in Cocoa GameUpdate(); GameRender(); } Thats obviously simplified a bit, but thats the gist of it. In Windows where I have full control over the application, it works great. Unfortunately Apple has their own way of doing things in Cocoa apps. When I first tried to implement my main loop in Cocoa, I couldn't figure out where to put it so I created my own NSApplication per this post. I threw my GameFrame() right in my run function and everything worked correctly. However, I don't feel like its the "right" way to do it. I would like to play nicely within Apple's ecosystem rather than trying to hack a solution that works. This article from apple describes the old way to do it, with an NSTimer, and the "new" way to do it using CVDisplayLink. I've hooked up the CVDisplayLink version, but it just feels....odd. I don't like the idea of my game being driven by the display rather than the other way around. Are my only two options to use a CVDisplayLink or overwrite my own NSApplication? Neither one of those solutions feels quite right.

    Read the article

  • deWitters Game loop in libgdx(Android)

    - by jaysingh
    I am a beginner and I want a complete example in LibGDX for android(Fixed time game loop) how to limit the framerate to 50 or 60. Also how to mangae interpolation between game state with simple example code e.g. deWiTTERS Game Loop: @Override public void render() { float deltaTime = Gdx.graphics.getDeltaTime(); Update(deltaTime); Render(deltaTime); } libgdx comments:- There is a Gdx.graphics.setVsync() method (generic = backend-independant), but it is not present in 0.9.1, only in the Nightlies. "Relying on vsync for fixed time steps is a REALLY bad idea. It will break on almost all hardware out there. See LwjglApplicationConfiguration, there's a flag in there that let s use toggle gpu/software vsynching. Play around with it." (Mario) NOTE that none of these limit the framerate to a specific value... if you REALLY need to limit the framerate for some reason, you'll have to handle it yourself by returning from render calls if xxx ms haven't passed since the last render call. li

    Read the article

  • Closed-loop Recommendation Engines: Analyst Insight report on Oracle Real-Time Decisions (RTD)

    - by Mike.Hallett(at)Oracle-BI&EPM
    In November 2011, Helena Schwenk of MWD Advisors, published her analysis on Oracle Real-Time Decisions.  She summarizes as follows: "In contrast to other popular approaches to implementing predictive analytics, RTD focuses on learning from each interaction and using these insights to adjust what is presented, offered or displayed to a customer. Likewise its capabilities for optimising decisions within the context of specific business goals and a report-driven framework for assessing the performance of models and decisions make it a strong contender for organisations that want to continuously improve decision making as part of a customer experience marketing, e-commerce optimisation and operational process efficiency initiative." This is an outstanding report to share with a prospect or client as it goes into great detail about the product and its capabilities.  It also highlights the differences in Oracle's Real-Time Decisions product vs. other closed loop recommendation engines. I encourage you to share this report with your clients and prospects. It can be downloaded directly from here - MWD Advisors Vendor Profile: Oracle Real-Time Decisions. (expires in November 2012) Highlights: "At the core of RTD lies a learning engine that combines business rules and adaptive predictive models to deliver recommendations to operational systems while simultaneously learning from experiences." "While closed-loop recommendation engines are becoming more prevalent... there are a number of features that distinguish RTD: It makes its decisions in the context of the business objectives, such as maximising customer revenue or reducing service costs Its support for operational integration offers organisations some flexibility in how they implement the offering."

    Read the article

  • How to slow down a sprite that updates every frame?

    - by xiaohouzi79
    I am going through a Allegro 5 tutorial which has a game loop. There is also a variable "active" which determines if a key is being held down. Thus if the left key is being held down active is on and it begins looping through the row on the sprite sheet that corresponds to moving left. The problem is that this logic is checked everytime the loop is performed thus at approximately 60 fps the three images that are used to do the left walking animation cycle round super fast which means my character looks like it is in a rush. Total beginner question: so what is the correct way to slow down the transition between sprites so that the walking looks like it is done at a moderate pace. Here is the code used to transition across the sprite between the three different phases of the person walking: if (active) { sourceX += al_get_bitmap_width(player) / 3; } else { sourceX = 32; } if (sourceX >= al_get_bitmap_width(player)) { sourceX = 0; } I can kind of guess what it should be in plain English: update sourceX only every certain part of a second but I can't think of how to put this into code.

    Read the article

  • PHP MYSQL loop to check if LicenseID Values are contained in mysql DB [closed]

    - by Jasper
    I have some troubles to find the right loop to check if some values are contained in mysql DB. I'm making a software and I want to add license ID. Each user has x keys to use. Now when the user start the client, it invokes a PHP page that check if the Key sent in the POST method is stored in DB or not. If that key isn't store than I need to check the number of his keys. If it's than X I'll ban him otherwise i add the new keys in the DB. I'm new with PHP and MYSQL. I wrote this code and I would know if I can improve it. <?php $user = POST METHOD $licenseID = POST METHOD $resultLic= mysql_query("SELECT id , idUser , idLicense FROM license WHERE idUser = '$user'") or die(mysql_error()); $resultNumber = mysql_num_rows($resultLic); $keyFound = '0'; // If keyfound is 1 the key is stored in DB while ($rows = mysql_fetch_array($resultLic,MYSQL_BOTH)) { //this loop check if the $licenseID is stored in DB or not for($i=0; $i< $resultNumber ; i++) { if($rows['idLicense'] === $licenseID) { //Just for the debug echo("License Found"); $keyFound = '1'; break; } //If key isn't in DB and there are less than 3 keys the new key will be store in DB if($keyfound == '0' && $resultNumber < 3) { mysql_query( Update users set ...Store $licenseID in Table) } // Else mean that the user want user another generated key (from the client) in the DB and i will be ban (It's wrote in TOS terms that they cant use the software on more than 3 different station) else { mysql_query( update users set ban ='1'.....etc ); } } ?> I know that this code seems really bad so i would know how i can improve it. Someone Could give me any advice? I choose to have 2 tables: users where all information about the users is, with fields id, username, password and another table license with fields id, idUsername, idLicense (the last one store license that the software generate)

    Read the article

  • Sneaky Javascript For Loop Bug

    - by Liam McLennan
    Javascript allows you to declare variables simply by assigning a value to an identify, in the same style as ruby: myVar = "some text"; Good javascript developers know that this is a bad idea because undeclared variables are assigned to the global object, usually window, making myVar globally visible. So the above code is equivalent to: window.myVar = "some text"; What I did not realise is that this applies to for loop initialisation as well. for (i = 0; i < myArray.length; i += 1) { } // is equivalent to for (window.i = 0; window.i < myArray.length; window.i += 1) { } Combine this with function calls nested inside of the for loops and you get some very strange behaviour, as the value of i is modified simultaneously by code in different scopes. The moral of the story is to ALWAYS declare javascript variables with the var keyword, even when intialising a for loop. for (var i = 0; i < myArray.length; i += 1) { }

    Read the article

  • C# Cursor stuck on busy state

    - by Ben
    So I implemented a fixed time step loop for my C# game. All it does at the moment is make a square bounce around the screen. The problem I'm having is that when I execute the program, the window doesn't allow me to close the program and the cursor is stuck on the busy icon. I have to go into visual studio and stop the program manually. Here's the loop at the moment public void run() { int updates = 0; int frames = 0; double msPerTick = 1000.0 / 60.0; double threshhold = 0; long lastTime = getCurrentTime(); long lastTimer = getCurrentTime(); while (true) { long currTime = getCurrentTime(); threshhold += (currTime - lastTime) / msPerTick; lastTime = currTime; while (threshhold >= 1) { update(); updates++; threshhold -= 1; } this.Refresh(); frames++; if ((getCurrentTime() - lastTimer) >= 1000) { this.Text = updates + " updates and " + frames + " frames per second"; updates = 0; frames = 0; lastTimer += 1000; } } }

    Read the article

  • How to loop through items in a js object?

    - by Blankman
    how can I loop through these items? var userCache = {}; userCache['john'] = {ID: 234, name: 'john', ... }; userCache['mary'] = {ID: 567, name: 'mary', ... }; userCache['douglas'] = {ID: 42, name: 'douglas', ... }; the length property doesn't work? userCache.length

    Read the article

  • How to break out of a nested parallel (OpenMP) Fortran loop idiomatically?

    - by J.F. Sebastian
    Here's sequential code: do i = 1, n do j = i+1, n if ("some_condition") then result = "here's result" return end if end do end do Is there a cleaner way to execute iterations of the outer loop concurrently other than: !$OMP PARALLEL private(i,j) !$OMP DO do i = 1, n if (found) goto 10 do j = i+1, n if (found) goto 10 if ("some_condition") then !$OMP CRITICAL !$OMP FLUSH if (.not.found) then found = .true. result = "here's result" end if !$OMP FLUSH !$OMP END CRITICAL goto 10 end if end do 10 continue end do !$OMP END DO NOWAIT !$OMP END PARALLEL

    Read the article

  • Why can't i loop through my json object using jquery?

    - by Pandiya Chendur
    I am using jquery to loop through json object... But some how it doesn't seem to work... Here is my code, success: function(jsonObj) { alert(jsonObj); for (var i = jsonObj.length - 1; i >= 0; i--) { var employee = jsonObj[i]; alert(employee.Emp_Name); When alerted my jsonObj i got [object Object] but when i alerted jsonObj.length it showed undefined any suggestion....

    Read the article

  • How do I break out of a loop in Scala?

    - by TiansHUo
    For Problem 4 of Project Euler How do I break out a loop? var largest=0 for(i<-999 to 1 by -1) { for (j<-i to 1 by -1) { val product=i*j if (largest>product) // I want to break out here else if(product.toString=product.toString.reverse) largest=largest max product } } And does anyone know how to turn nested for loops into tail recursion?

    Read the article

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