Search Results

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

Page 4/68 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Watching setTimeout loops so that only one is running at a time.

    - by DA
    I'm creating a content rotator in jQuery. 5 items total. Item 1 fades in, pauses 10 seconds, fades out, then item 2 fades in. Repeat. Simple enough. Using setTimeout I can call a set of functions that create a loop and will repeat the process indefinitely. I now want to add the ability to interrupt this rotator at any time by clicking on a navigation element to jump directly to one of the content items. I originally started going down the path of pinging a variable constantly (say every half second) that would check to see if a navigation element was clicked and, if so, abandon the loop, then restart the loop based on the item that was clicked. The challenge I ran into was how to actually ping a variable via a timer. The solution is to dive into JavaScript closures...which are a little over my head but definitely something I need to delve into more. However, in the process of that, I came up with an alternative option that actually seems to be better performance-wise (theoretically, at least). I have a sample running here: http://jsbin.com/uxupi/14 (It's using console.log so have fireBug running) Sample script: $(document).ready(function(){ var loopCount = 0; $('p#hello').click(function(){ loopCount++; doThatThing(loopCount); }) function doThatOtherThing(currentLoopCount) { console.log('doThatOtherThing-'+currentLoopCount); if(currentLoopCount==loopCount){ setTimeout(function(){doThatThing(currentLoopCount)},5000) } } function doThatThing(currentLoopCount) { console.log('doThatThing-'+currentLoopCount); if(currentLoopCount==loopCount){ setTimeout(function(){doThatOtherThing(currentLoopCount)},5000); } } }) The logic being that every click of the trigger element will kick off the loop passing into itself a variable equal to the current value of the global variable. That variable gets passed back and forth between the functions in the loop. Each click of the trigger also increments the global variable so that subsequent calls of the loop have a unique local variable. Then, within the loop, before the next step of each loop is called, it checks to see if the variable it has still matches the global variable. If not, it knows that a new loop has already been activated so it just ends the existing loop. Thoughts on this? Valid solution? Better options? Caveats? Dangers? UPDATE: I'm using John's suggestion below via the clearTimeout option. However, I can't quite get it to work. The logic is as such: var slideNumber = 0; var timeout = null; function startLoop(slideNumber) { ...do stuff here to set up the slide based on slideNumber... slideFadeIn() } function continueCheck(){ if (timeout != null) { // cancel the scheduled task. clearTimeout(timeout); timeout = null; return false; }else{ return true; } }; function slideFadeIn() { if (continueCheck){ // a new loop hasn't been called yet so proceed... // fade in the LI $currentListItem.fadeIn(fade, function() { if(multipleFeatures){ timeout = setTimeout(slideFadeOut,display); } }); }; function slideFadeOut() { if (continueLoop){ // a new loop hasn't been called yet so proceed... slideNumber=slideNumber+1; if(slideNumber==features.length) { slideNumber = 0; }; timeout = setTimeout(function(){startLoop(slideNumber)},100); }; startLoop(slideNumber); The above kicks of the looping. I then have navigation items that, when clicked, I want the above loop to stop, then restart with a new beginning slide: $(myNav).click(function(){ clearTimeout(timeout); timeout = null; startLoop(thisItem); }) If I comment out 'startLoop...' from the click event, it, indeed, stops the initial loop. However, if I leave that last line in, it doesn't actually stop the initial loop. Why? What happens is that both loops seem to run in parallel for a period. So, when I click my navigation, clearTimeout is called, which clears it.

    Read the article

  • As our favorite imperative languages gain functional constructs, should loops be considered a code s

    - by Michael Buen
    In allusion to Dare Obasanjo's impressions on Map, Reduce, Filter (Functional Programming in C# 3.0: How Map/Reduce/Filter can Rock your World) "With these three building blocks, you could replace the majority of the procedural for loops in your application with a single line of code. C# 3.0 doesn't just stop there." Should we increasingly use them instead of loops? And should be having loops(instead of those three building blocks of data manipulation) be one of the metrics for coding horrors on code reviews? And why? [NOTE] I'm not advocating fully functional programming on those codes that could be simply translated to loops(e.g. tail recursions) Asking for politer term. Considering that the phrase "code smell" is not so diplomatic, I posted another question http://stackoverflow.com/questions/432492/whats-the-politer-word-for-code-smell about the right word for "code smell", er.. utterly bad code. Should that phrase have a place in our programming parlance?

    Read the article

  • Why use infinite loops?

    - by Moishe
    Another poster asked about preferred syntax for infinite loops. A follow-up question: Why do you use infinite loops in your code? I typically see a construct like this: for (;;) { int scoped_variable = getSomeValue(); if (scoped_variable == some_value) { break; } } Which lets you get around not being able to see the value of scoped_variable in the for or while clause. What are some other uses for "infinite" loops?

    Read the article

  • How can I reduce the number of loops in this VIEW in Rails when using :collection?

    - by Angela
    I am using the :collection to go through all the Contacts that are part of a given Campaign. But within that Campaign I check for three different Models (each with their own partial). Feels like I am going through the list of Contacts 3x. How can I make this alot leaner? <h2>These are past due:</h2> <% @campaigns.each do |campaign| %> <h3>Campaign: <%= link_to campaign.name, campaign %></h3> <strong>Emails in this Campaign:</strong> <% for email in campaign.emails %> <h4><%= link_to email.title, email %> <%= email.days %> days</h4> <% @contacts= campaign.contacts.find(:all, :order => "date_entered ASC" )%> <!--contacts collection--> <!-- render the information for each contact --> <%= render :partial => "contact_email", :collection => @contacts, :locals => {:email => email} %> <% end %> Calls in this Campaign: <% for call in campaign.calls %> <h4><%= link_to call.title, call %> <%= call.days %> days</h4> <% @contacts= campaign.contacts.find(:all, :order => "date_entered ASC" )%> <!--contacts collection--> <!-- render the information for each contact --> <%= render :partial => "contact_call", :collection => @contacts, :locals => {:call => call} %> <% end %> Letters in this Campaign: <% for letter in campaign.letters %> <h4><%= link_to letter.title, letter %> <%= letter.days %> days</h4> <% @contacts= campaign.contacts.find(:all, :order => "date_entered ASC" )%> <!--contacts collection--> <!-- render the information for each contact --> <%= render :partial => "contact_letter", :collection => @contacts, :locals => {:letter => letter} %> <% end %> <% end %>

    Read the article

  • Cursor loops; How to perform something at start/end of loop 1 time only?

    - by James.Elsey
    I've got the following in one of my Oracle procedures, I'm using it to generate XML -- v_client_addons is set to '' to avoid null error OPEN C_CLIENT_ADDONS; LOOP FETCH C_CLIENT_ADDONS INTO CLIENT_ADDONS; EXIT WHEN C_CLIENT_ADDONS%NOTFOUND; BEGIN v_client_addons := v_client_addons || CLIENT_ADDONS.XML_DATA; END; END LOOP; CLOSE C_CLIENT_ADDONS; -- Do something later with v_client_addons The loop should go through my cursor and pick out all of the XML values to display, such as : <add-on name="some addon"/> <add-on name="another addon"/> What I would like to achieve is to have an XML start/end tag inside this loop, so I would have the following output <addons> <add-on name="some addon"/> <add-on name="another addon"/> </addons> How can I do this without having the <addons> tag after every line? If there are no addons in the cursor (cursor is empty), then I would like to skip this part enitrely

    Read the article

  • Is there a way to add unique items to an array without doing a ton of comparisons?

    - by hydroparadise
    Please bare with me, I want this to be as language agnostic as possible becuase of the languages I am working with (One of which is a language called PowerOn). However, most languanges support for loops and arrays. Say I have the following list in an aray: 0x 0 Foo 1x 1 Bar 2x 0 Widget 3x 1 Whatsit 4x 0 Foo 5x 1 Bar Anything with a 1 should be uniqely added to another array with the following result: 0x 1 Bar 1x 1 Whatsit Keep in mind this is a very elementry example. In reality, I am dealing with 10's of thousands of elements on the old list. Here is what I have so far. Pseudo Code: For each element in oldlist For each element in newlist Compare If values oldlist.element equals newlist.element, break new list loop If reached end of newlist with with nothing equal from oldlist, add value from old list to new list End End Is there a better way of doing this? Algorithmicly, is there any room for improvement? And as a bonus qeustion, what is the O notation for this type of algorithm (if there is one)?

    Read the article

  • Postfix "loops back to myself" error on relay to another IP address on same machine

    - by Nic Wolff
    I'm trying to relay all mail for one domain "ourdomain.tld" from Postfix running on port 2525 of one interface to another SMTP server running on port 25 of another interface on the same machine. However, when a message is received for that domain, we're getting a "mail for loops back to myself" error. Below are netstat and postconf, the contents of our /etc/postfix/transport file, and the error that Postfix is logging. (The high bytes of each IP address are XXXed out.) Am I missing something obvious? Thanks - # netstat -ln -A inet Proto Recv-Q Send-Q Local Address Foreign Address State ... tcp 0 0 XXX.XXX.138.209:25 0.0.0.0:* LISTEN tcp 0 0 XXX.XXX.138.210:2525 0.0.0.0:* LISTEN # postconf -d | grep mail_version mail_version = 2.8.4 # postconf -n alias_maps = hash:/etc/aliases allow_mail_to_commands = alias,forward bounce_queue_lifetime = 0 command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 default_privs = nobody default_process_limit = 200 html_directory = no inet_interfaces = XXX.XXX.138.210 local_recipient_maps = local_transport = error:local mail delivery is disabled mail_owner = postfix mailbox_size_limit = 0 mailq_path = /usr/bin/mailq manpage_directory = /usr/local/man message_size_limit = 10240000 mydestination = mydomain = ourdomain.tld myhostname = ourdomain.tld mynetworks = XXX.XXX.119.0/24, XXX.XXX.138.0/24, XXX.XXX.136.128/25 myorigin = ourdomain.tld newaliases_path = /usr/bin/newaliases queue_directory = /var/spool/postfix readme_directory = /etc/postfix recipient_delimiter = + relay_domains = ourdomain.tld relay_recipient_maps = sample_directory = /etc/postfix sendmail_path = /usr/sbin/sendmail setgid_group = postdrop smtpd_authorized_verp_clients = $mynetworks smtpd_recipient_limit = 10000 transport_maps = hash:/etc/postfix/transport unknown_local_recipient_reject_code = 450 # cat /etc/postfix/transport ourdomain.tld relay:[XXX.XXX.138.209]:25 # tail -f /var/log/maillog ... Aug 2 23:58:36 va4 postfix/smtp[9846]: 9858A758404: to=<nicwolff@... >, relay=XXX.XXX.138.209[XXX.XXX.138.209]:25, delay=1.1, delays=0.08/0.01/1/0, dsn=5.4.6, status=bounced (mail for [XXX.XXX.138.209]:25 loops back to myself)

    Read the article

  • Need Help in optimizing a loop in C [migrated]

    - by WedaPashi
    I am trying to draw a Checkerboard pattern on a lcd using a GUI library called emWin. I have actually managed to draw it using the following code. But having these many loops in the program body for a single task, that too in the internal flash of the Microcontroller is not a good idea. Those who have not worked with emWin, I will try and explain a few things before we go for actual logic. GUI_REST is a structure which id define source files of emWin and I am blind to it. Rect, REct2,Rec3.. and so on till Rect10 are objects. Elements of the Rect array are {x0,y0,x1,y1}, where x0,y0 are starting locations of rectangle in X-Y plane and x1, y1 are end locations of Rectangle in x-Y plane. So, Rect={0,0,79,79} is a rectangle starts at top left of the LCD and is upto (79,79), so its a square basically. The function GUI_setBkColor(int color); sets the color of the background. The function GUI_setColor(int color); sets the color of the foreground. GUI_WHITE and DM_CHECKERBOARD_COLOR are two color values, #defineed GUI_FillRectEx(&Rect); will draw the Rectangle. The code below works fine but I want to make it smarter. GUI_RECT Rect = {0, 0, 79, 79}; GUI_RECT Rect2 = {80, 0, 159, 79}; GUI_RECT Rect3 = {160, 0, 239, 79}; GUI_RECT Rect4 = {240, 0, 319, 79}; GUI_RECT Rect5 = {320, 0, 399, 79}; GUI_RECT Rect6 = {400, 0, 479, 79}; GUI_RECT Rect7 = {480, 0, 559, 79}; GUI_RECT Rect8 = {560, 0, 639, 79}; GUI_RECT Rect9 = {640, 0, 719, 79}; GUI_RECT Rect10 = {720, 0, 799, 79}; WM_SelectWindow(Win_DM_Main); GUI_SetBkColor(GUI_BLACK); GUI_Clear(); for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(GUI_WHITE); else GUI_SetColor(DM_CHECKERBOARD_COLOR); GUI_FillRectEx(&Rect); Rect.y0 += 80; Rect.y1 += 80; } /* for(j=0,j<11;j++) { for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(GUI_WHITE); else GUI_SetColor(DM_CHECKERBOARD_COLOR); GUI_FillRectEx(&Rect); Rect.y0 += 80; Rect.y1 += 80; } Rect.x0 += 80; Rect.x1 += 80; } */ for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(DM_CHECKERBOARD_COLOR); else GUI_SetColor(GUI_WHITE); GUI_FillRectEx(&Rect2); Rect2.y0 += 80; Rect2.y1 += 80; } for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(GUI_WHITE); else GUI_SetColor(DM_CHECKERBOARD_COLOR); GUI_FillRectEx(&Rect3); Rect3.y0 += 80; Rect3.y1 += 80; } for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(DM_CHECKERBOARD_COLOR); else GUI_SetColor(GUI_WHITE); GUI_FillRectEx(&Rect4); Rect4.y0 += 80; Rect4.y1 += 80; } for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(GUI_WHITE); else GUI_SetColor(DM_CHECKERBOARD_COLOR); GUI_FillRectEx(&Rect5); Rect5.y0 += 80; Rect5.y1 += 80; } for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(DM_CHECKERBOARD_COLOR); else GUI_SetColor(GUI_WHITE); GUI_FillRectEx(&Rect6); Rect6.y0 += 80; Rect6.y1 += 80; } for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(GUI_WHITE); else GUI_SetColor(DM_CHECKERBOARD_COLOR); GUI_FillRectEx(&Rect7); Rect7.y0 += 80; Rect7.y1 += 80; } for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(DM_CHECKERBOARD_COLOR); else GUI_SetColor(GUI_WHITE); GUI_FillRectEx(&Rect8); Rect8.y0 += 80; Rect8.y1 += 80; } for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(GUI_WHITE); else GUI_SetColor(DM_CHECKERBOARD_COLOR); GUI_FillRectEx(&Rect9); Rect9.y0 += 80; Rect9.y1 += 80; } for(i = 0; i < 6; i++) { if(i%2 == 0) GUI_SetColor(DM_CHECKERBOARD_COLOR); else GUI_SetColor(GUI_WHITE); GUI_FillRectEx(&Rect10); Rect10.y0 += 80; Rect10.y1 += 80; }

    Read the article

  • IndexOutofRangeException while using WriteLine in nested Parallel.For loops

    - by Umar Asif
    I am trying to write kinect depth data to a text file using nested Parallel.For loops with the following code. However, it gives IndexOutofRangeException. The code works perfect if using simple for loops but it hangs the UI since the depth format is set to 640x480 causing the loops to write 307200 lines in the text file at 30fps. Therefore, I switched to Parallel. For scheme. If I omit the writeLine command from the nested loops, the code works fine, which indicates that the IndexOutofRangeException is arising at the writeline command. I do not know how to troubleshoot this. Please advise. Any better workarounds to avoid UI freezing? Thanks. using (DepthImageFrame depthImageframe = d.OpenDepthImageFrame()) { if (depthImageframe == null) return; depthImageframe.CopyPixelDataTo(depthPixelData); swDepth = new StreamWriter(@"E:\depthData.txt", false); int i = 0; Parallel.For(0, depthImageframe.Width, delegate(int x) { Parallel.For(0, depthImageframe.Height, delegate(int y) { p[i] = sensor.MapDepthToSkeletonPoint(depthImageframe.Format, x, y, depthPixelData[x + depthImageframe.Width * y]); swDepth.WriteLine(i + "," + p[k].X + "," + p[k].Y + "," + p[k].Z); i++; }); }); swDepth.Close(); } }

    Read the article

  • Two foreach loops, ideea for my code please

    - by webmasters
    Please give me an ideea for my code, its a simple links script. TY I need two foreach loops, one which loops my sites and one which loops my anchors. So i'll have <li>link to site1 and anchor to site1</li> <li>link to site2 and anchor to site2</li> <li>link to site3 and anchor to site3</li> $currentsite = ''.bloginfo('wpurl').''; $mysites = array('http://site1.com', 'http://site2.com', 'http://site3.com'); $myanchors = array('anchor1','anchor2','anchor3'); foreach($mysites as $mysite) ****** i need a foreach loop for the anchors array ******* { if ( $mysite !== $currentsite ){echo '<li><a href="'.$mysite.'" title="'.$myanchor.'">'.$myanchor.'</a></li>';} }

    Read the article

  • in DDD (gdb) how to skip passed loops

    - by Andrei
    During many, sometimes inundating, debugging sessions using DDD, I stumble upon loops. And I keep pressing next to get passed it, and if there are many iterations, I just set a break point right after it, and press "continue." Is there any other way to go passed loops? Thanks

    Read the article

  • Efficiency of nested Loop

    - by didxga
    See the following snippet: //first nested loops for(int i=0;i<10;i++) { for(int j=1;j<1000000;j++) { //do some stuff } } //second nested loops for(int i=0;i<1000000;i++) { for(int j=1;j<10;j++) { //do some stuff } } I am wondering why the first nested loops is running slower than the second one? Regards!

    Read the article

  • in DDD (gdb) how to skip past loops

    - by Andrei
    During many, sometimes inundating, debugging sessions using DDD, I stumble upon loops. And I keep pressing next to get past it, and if there are many iterations, I just set a break point right after it, and press "continue." Is there any other way to go past loops? Thanks

    Read the article

  • T-SQL Tuesday # 16 : This is not the aggregate you're looking for

    - by AaronBertrand
    This week, T-SQL Tuesday is being hosted by Jes Borland ( blog | twitter ), and the theme is " Aggregate Functions ." When people think of aggregates, they tend to think of MAX(), SUM() and COUNT(). And occasionally, less common functions such as AVG() and STDEV(). I thought I would write a quick post about a different type of aggregate: string concatenation. Even going back to my classic ASP days, one of the more common questions out in the community has been, "how do I turn a column into a comma-separated...(read more)

    Read the article

  • generate parent child relation from the array to print a multi-level menu?

    - by Karthick Selvam
    How to get parent child relation from this array to print a multi-level menu $menus = array ( 0 => array ( 'id'=>0, 'check' => 1, 'display' =>'Arete Home', 'ordering' => -10, 'parent' => none, ), 1 => array ( 'id'=>1, 'check' => 1, 'display' => 'Submit Paper', 'ordering' => -10, 'parent' => 2, 'subordering' => -10, ), 2 => array ( 'id'=>2, 'check' => 1, 'display' => 'Buy Now', 'ordering' => -10, 'parent' => 1, 'subordering' => -10, ), 1461 => array ( 'id'=>1461, 'check' => 1, 'display' => 'Where are We?', 'ordering' => -10, 'parent' => 2, 'subordering' => -10, ), 1463 => array ( 'id'=>1463, 'check' => 1, 'display' =>' About Me?', 'ordering' => -10, 'parent' => 2, 'subordering' => -10, ), 1464 => array ( 'id'=>1464, 'check' => 1, 'display' => 'About You?', 'ordering' => -10, 'parent' => 2, 'subordering' => -10, ), 1465 => array ( 'id'=>1465, 'check' => 1, 'display' => 'About who?', 'ordering' => -10, 'parent' => 1, 'subordering' => -10, ), ); code sample: foreach($menus as $id=>$values) { $values['parent']=isset($values['parent']) ? $values['parent'] : 0; $menus[$values['parent']]['childs'][$id]=$values; unset($menus[$id]); } foreach($menus as $id1=>$value2) { $value2['parent']=isset($value2['parent']) ? $value2['parent'] : 0; $menus[$value2['parent']]['childs'][$id1]=$value2; unset($menus[$id1]); }

    Read the article

  • comparison of an unsigned variable to 0

    - by user2651062
    When I execute the following loop : unsigned m; for( m = 10; m >= 0; --m ){ printf("%d\n",m); } the loop doesn't stop at m==0, it keeps executing interminably, so I thought that reason was that an unsigned cannot be compared to 0. But when I did the following test unsigned m=9; if(m >= 0) printf("m is positive\n"); else printf("m is negative\n"); I got this result: m is positive which means that the unsigned variable m was successfully compared to 0. Why doesn't the comparison of m to 0 work in the for loop and works fine elsewhere?

    Read the article

  • Why does the instruction "do" require a "while"?

    - by 909 Niklas
    Since this statement is so common: while (true) (Java) or while (1) (C) or sometimes for (;;) Why is there not a single instruction for this? I could think that an instruction that could do it is just do but do requires a while at the end of the block but it would be more logical to write an infinite loop like this do { //loop forever } Why not? AFAIK the instruction do always requires a while at the end but if we could use it like above then it would be a clear way to define something like while (true) which I think should not be written like that (or for (;;)).

    Read the article

  • Finding "spare time" in a day from within a list of events

    - by MFB
    I have a list of events which is always sorted chronologically. The start time is always followed by the end time. Times are strings formatted as 'HHmmss'. // list of events var events = [ '010000', // start '013000', // end... '053000', '060000', '161500', '184500'] // desired output var spares = [ '000000', // start '010000', // end... '013000', '053000', '060000', '161500', '184500', '235959'] How can I programmatically create a new list of "spare time" from 000000 to 235959? PS I'm trying to do this in Javascript, but any conceptual answer or pseudo code would be helpful too.

    Read the article

  • Prevent auto forwarding NDR loops

    - by DemonWareXT
    a week ago we experienced a really sweet problem at a client of ours. They are a school with around 1200 users, and everyone of them has auto forwarding for all mail activated. We use Exchange 2010 Now a few of the users where able to make NDR loops by adding 2 different, wrong, destinations. We had around 80k mails sent within a few hours. Not very practical. My question is, does anyone know a good way to prevent something like this. I have found 2 ways, which both fail for their own reasons We could manage the auto forwarding on the exchange host itself, which should prevent this looping problem someone said. But 1200 Users, not on my watch. There is a Powershell script out in the wild which should work against that, but my employers want something more "professional" Thank you very much for your support Linus

    Read the article

  • Randomly and uniquely iterating over a range

    - by Synetech
    Say you have a range of values (or anything else) and you want to iterate over the range and stop at some indeterminate point. Because the stopping value could be anywhere in the range, iterating sequentially is no good because it causes the early values to be accessed more often than later values (which is bad for things that wear out), and also because it reduces performance since it must traverse extra values. Randomly iterating is better because it will (on average) increase the hit-rate so that fewer values have to be accessed before finding the right one, and also distribute the accesses more evenly (again, on average). The problem is that the standard method of randomly jumping around will result in values being accessed multiple times, and has no automatic way of determining when each value has been checked and thus the whole range has been exhausted. One simplified and contrived solution could be to make a list of each value, pick one at random, then remove it. Each time through the loop, you pick one fromt he set of remaining items. Unfortunately this only works for small lists. As a (forced) example, say you are creating a game where the program tries to guess what number you picked and shows how many guess it took. The range is between 0-255 and instead of asking Is it 0? Is it 1? Is it 2?…, you have it guess randomly. You could create a list of 255 numbers, pick randomly and remove it. But what if the range was between 0-232? You can’t really create a 4-billion item list. I’ve seen a couple of implementations RNGs that are supposed to provide a uniform distribution, but none that area also supposed to be unique, i.e., no repeated values. So is there a practical way to randomly, and uniquely iterate over a range?

    Read the article

  • Does it make a difference if I declare variables inside or outside a loop in Java?

    - by Puckl
    Does it make a difference if I declare variables inside or outside a loop in Java? Is this for(int i = 0; i < 1000; i++) { int temporaryValue = someMethod(); list.add(temporaryValue) } equal to this (with respect to memory usage)? int temporaryValue = 0; for(int i = 0; i < 1000; i++) { temporaryValue = someMethod(); list.add(temporaryValue) } And what if the temporary variable is for example an ArrayList? for(int i = 0; i < 1000; i++) { ArrayList<Integer> array = new ArrayList<Integer>(); fillArray(array); // do something with the array }

    Read the article

  • VB 2010 LOGIN 3-TIMES LOOP [migrated]

    - by stargaze07
    How to put a loop on my log in code it's like the program will end if the user inputs a wrong password/username for the third time? At this point I'm having a hard time putting the loop code. This is my LogIn Code in VB 2010 Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click Me.Refresh() Dim login = Me.TblUserTableAdapter1.UsernamePasswordString(txtUser.Text, txtPass.Text) If login Is Nothing Then MessageBox.Show("Incorrect login details", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Else Dim ok As DialogResult ok = MessageBox.Show("Login Successful", "Dantiña's Catering Maintenance System", MessageBoxButtons.OK, MessageBoxIcon.Information) MMenu.Show() MMenu.lblName.Text = "Welcome " & Me.txtUser.Text & " !" If txtPass.Text <> "admin" Then MMenu.Button1.Enabled = False ProdMaintenance.GroupBox1.Visible = True MMenu.Button2.Enabled = True MMenu.Button3.Enabled = True MMenu.Button4.Enabled = True Else MMenu.Button1.Enabled = True ProdMaintenance.GroupBox1.Visible = True MMenu.Button2.Enabled = True MMenu.Button3.Enabled = True MMenu.Button4.Enabled = True End If Me.Refresh() Me.Hide() End If End Sub

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >