Search Results

Search found 10235 results on 410 pages for 'inner loop'.

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

  • jQuery loop through data() object

    - by bartclaeys
    Is it possible to loop through a data() object? Suppose this is my code: $('#mydiv').data('bar','lorem'); $('#mydiv').data('foo','ipsum'); $('#mydiv').data('cam','dolores'); How do I loop through this? Can each() be used for this?

    Read the article

  • Loop over array and set all vars to false or true in javascript

    - by Sixfoot Studio
    Hi All, I need to loop over my array and set all the vars to false or true. I have tried numerous options, none of which are working and it's clearly my lack of javascript syntax knowledge..Please take a look at this: var closeAllCells = [IncomeOpen = "false", RehabOpen = "false", AttendantCareOpen = "false", HomeMaintenanceOpen = "false", DependantCareOpen = "false", IndexationOpen = "false", DeathFuneralOpen = "false", ComprehensiveOpen = "false", CollisionOpen = "false", LiabilityOpen = "false", DCPDOpen = "false"]; So my thinking is that I can just loop over this as follows for (var i=0;i<closeAllCells.length;i++) { closeAllCells[i] = true; // or false if I wished }

    Read the article

  • Python how to convert this for loop into a while loop

    - by user1690198
    I have this for a for loop which I made I was wondering how I would write so it would work with a while loop. def scrollList(myList): negativeIndices=[] for i in range(0,len(myList)): if myList[i]<0: negativeIndices.append(i) return negativeIndices So far I have this def scrollList2(myList): negativeIndices=[] i= 0 length= len(myList) while i != length: if myList[i]<0: negativeIndices.append(i) i=i+1 return negativeIndices

    Read the article

  • dynamic naming of UIButtons within a loop - objective-c, iphone sdk

    - by von steiner
    Dear Members, Scholars. As it may seem obvious I am not armed with Objective C knowledge. Levering on other more simple computer languages I am trying to set a dynamic name for a list of buttons generated by a simple loop (as the following code suggest). Simply putting it, I would like to have several UIButtons generated dynamically (within a loop) naming them dynamically, as well as other related functions. button1,button2,button3 etc.. After googling and searching Stackoverlow, I haven't arrived to a clear simple answer, thus my question. - (void)viewDidLoad { // This is not Dynamic, Obviously UIButton *button0 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button0 setTitle:@"Button0" forState:UIControlStateNormal]; button0.tag = 0; button0.frame = CGRectMake(0.0, 0.0, 100.0, 100.0); button0.center = CGPointMake(160.0,50.0); [self.view addSubview:button0]; // I can duplication the lines manually in terms of copy them over and over, changing the name and other related functions, but it seems wrong. (I actually know its bad Karma) // The question at hand: // I would like to generate that within a loop // (The following code is wrong) float startPointY = 150.0; // for (int buttonsLoop = 1;buttonsLoop < 11;buttonsLoop++){ NSString *tempButtonName = [NSString stringWithFormat:@"button%i",buttonsLoop]; UIButton tempButtonName = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [tempButtonName setTitle:tempButtonName forState:UIControlStateNormal]; tempButtonName.tag = tempButtonName; tempButtonName.frame = CGRectMake(0.0, 0.0, 100.0, 100.0); tempButtonName.center = CGPointMake(160.0,50.0+startPointY); [self.view addSubview:tempButtonName]; startPointY += 100; } }

    Read the article

  • Loop with a while

    - by ookla
    Very basic question.. but I'm missing the point.. I have this data on my table: ID SITEID SECTION 1 1 posts 2 2 posts 3 1 aboutme 4 1 contact 5 2 questions The output is an array. I can't change it. I want to make this output on php with a single for loop with that array: <h1> sections for site 1 </h1> posts aboutme contact <h1>sections for site 2 </h1> posts questions I'm trying to do something like this, where $sectionsArray is my output. And I want to check if siteid is the same, then make a loop.. for ($j=0;$j<sizeof($sectionsArray);$j++) { while (siteid==1){ echo "<h1>'.$sectionsArray['siteid'].'</h1>'; } echo "<A href='section.php?id='.$sectionsArray['id'].' '">'.$sectionsArray['section'].'</a>; } But I don't get the logic of "grouping" the results with a while.. INSIDE a loop. Any light will be welcome. Thanks

    Read the article

  • Text Hints with JQuery and JavaScript for loop

    - by lpdahito
    Hey guys! I'm developing a small app where i ask users to put some info. I want to show text hints in the input fields. I do this in a for loop... When the page is loaded, the hints are displayed correctly but nothing happens on 'focus' and 'blur' events... I'm wondering why since when I don't use a 'for loop' in my js code, everything works find... By the way the reason I use a for loop is because I don't want to repeat myself following 'DRY' principles... Thx for your help! LP Here's the code: <script src="/javascripts/jquery.js" type="text/javascript"></script> <script type="text/javascript"> var form_elements = ['#submission_url', '#submission_email', '#submission_twitter'] var text_hints = ['Website Address', 'Email Address', 'Twitter Username (optional)'] $(document).ready(function(){ for(i=0; i<3; i++) { $(form_elements[i]).val(text_hints[i]); $(form_elements[i]).focus(function(i){ if ($(this).val() == text_hints[i]) { $(this).val(''); } }); $(form_elements[i]).blur(function(i){ if ($(this).val() != text_hints[i]) { $(this).val(text_hints[i]); } }); } }); </script>

    Read the article

  • Basic syntax for an animation loop?

    - by Moshe
    I know that jQuery, for example, can do animation of sorts. I also know that at the very core of the animation, there must me some sort of loop doing the animation. What is an example of such a loop? A complete answer should ideally answer the following questions: What is a basic syntax for an effective animation recursion that can animate a single property of a particular object at a time? The function should be able to vary its target object and property of the object. What arguments/parameters should it take? What is a good range of reiterating the loop? In milliseconds? (Should this be a parameter/argument to the function?) REMEMBER: The answer is NOT necessarily language specific, but if you are writing in a specific language, please specify which one. Error handling is a plus. {Nothing is more irritating (for our purposes) than an animation that does something strange, like stopping halfway through.} Thanks!

    Read the article

  • Having a different action for each button dynamically created in a loop

    - by Oliver
    Hi, use this website a lot but first time posting. My program creates a number of buttons depending on the number of records in a file. E.g. 5 records, 5 buttons. The buttons are being created but i'm having a problem with the action listener. If add the action listener in the loop every button does the same thing; but if I add the action listener outside the loop it just adds the action listener to last button. Any ideas? Here is what I have code-wise (I've just added the for loop to save space): int j=0; for(int i=0; i<namesA.size(); i++) { b = new JButton(""+namesA.get(i)+""); conPanel.add(b); conFrame.add(conPanel); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae2){ System.out.println(namesA.get(j)); } }}); j++; } Much Appreciated

    Read the article

  • Python: For loop problem

    - by James
    I have a PSP page with html embedded. I need to place another for loop so i can insert another %s next to background-color: which will instert a appropriate colour to colour in the html table. For example i need to insert for z in colours so it can loop over the colours list and insert the correct colour. Where ever i try to insert the for loop it doesnt seem to work it most commonly colours each cell in the table 60 times then moves onto the next cell and repeats itself and crashes my web browser. The colours are held in a table called colours. code below: <table> <% s = ''.join(aa[i] for i in table if i in aa) for i in range(0, len(s), 60): req.write('<tr><td><TT>%04d</td>' % (i+1)); for k in s[i:i+60]: req.write('<TT><td><TT><font style="background-color:">%s<font></td>' % (k)); req.write('</TT></tr>') #end %> </table>

    Read the article

  • Problem with for-loop in python

    - by Protean
    This code is supposed to be able to sort the items in self.array based upon the order of the characters in self.order. The method sort runs properly until the third iteration, unil for some reason the for loop seems to repeat indefinitely. What is going on here? class sorting_class: def __init__(self): self.array = ['ca', 'bd', 'ac', 'ab'] #An array of strings self.arrayt = [] self.globali = 0 self.globalii = 0 self.order = ['a', 'b', 'c', 'd'] #Order of characters self.orderi = 0 self.carry = [] self.leave = [] self.sortedlist = [] def sort(self): for arrayi in self.arrayt: #This should only loop for the number items in self.arrayt. However, the third time this is run it seems to loop indefinitely. print ('run', arrayi) #Shows the problem if self.order[self.orderi] == arrayi[self.globali]: self.carry.append(arrayi) else: if self.globali != 0: self.leave.append(arrayi) def srt(self): self.arrayt = self.array my.sort() #First this runs the first time. while len(self.sortedlist) != len(self.array): if len(self.carry) == 1: self.sortedlist.append(self.carry) self.arrayt = self.leave self.leave = [] self.carry = [] self.globali = 1 self.orderi = 0 my.sort() elif len(self.carry) == 0: if len(self.leave) != 0: #Because nothing matches 'aa' during the second iteration, this code runs the third time" self.arrayt = self.leave self.globali = 1 self.orderi += 1 my.sort() else: self.arrayt = self.array self.globalii += 1 self.orderi = self.globalii self.globali = 0 my.sort() self.orderi = 0 else: #This is what runs the second time. self.arrayt = self.carry self.carry = [] self.globali += 1 my.sort() my = sorting_class() my.srt()

    Read the article

  • using a While loop to control the value of a keyframe in a timeline in Javafx

    - by dragoknight
    i want to create an animation where the ball will move in one of the 4 sectors of a circle randomly.this will happen 5 times.so,i create a while loop(i<5) and call the random function.i then create an if loop and attach some x and y values according to the random fn value.i then create an timeline object inside the while loop and in the key frame value,i use these x and y values.but when i run the program,what happens is that all the values are being created(x and y values seen through println) but only the last x and y value(for i=5)is being rendered in the screen.the animations for the previous values(1<=i<=4)are not being rendered.Please advise where have i gone wrong? public function run(args:String[]) { var i=0; while(i<5) { var z=gety(); println(z); // var relativeTime:Duration=0s; if(z==1) {xbind=120; ybind=80; } else if(z==2) {xbind=120; ybind=120; } else if(z==3) { xbind=80; ybind=120; } else if(z==4) { xbind=80; ybind=80; } var t:Timeline=Timeline{ //time: bind pos with inverse; repeatCount: Timeline.INDEFINITE autoReverse: true keyFrames: [ KeyFrame{ time: 0s values: [ x => 100.0,y => 100.0]}, KeyFrame{time: 2s values:[x => xbind tween Interpolator.LINEAR, y => ybind tween Interpolator.LINEAR,] }, ] }//end timeline i++; t.play(); Thread.sleep(2000); }//end while }

    Read the article

  • Internal loop only runs once, containing loop runs endlessly

    - by Mark
    noob question I'm afraid. I have a loop that runs and rotates the hand of a clock and an internal loop that checks the angle of the hand if it is 90, 180, 270 and 360. On these 4 angles the corresponding div is displayed and its siblings removed. The hand loops and loops eternally, which is what I want, but the angle check only runs the loop once through the whole 360. As the hand passes through the angles it is correctly displaying and removing divs but is doesn't continue after the first revolution of the clock. I've obviously messed up somewhere and there is bound to be a more efficient way of doing all this. I am using jQueryRotate.js for my rotations. Thanks for your time. jQuery(document).ready(function(){ var angle = 0; setInterval(function(){ jQuery("#hand").rotate(angle); function movehand(){ if (angle == 90) { jQuery("#intervention").fadeIn().css("display","block").siblings().css("display","none"); } else if (angle == 180) { jQuery("#management").fadeIn().css("display","block").siblings().css("display","none"); } else if (angle == 270) { jQuery("#prevention").fadeIn().css("display","block").siblings().css("display","none"); } else if (angle == 360) { jQuery("#reaction").fadeIn().css("display","block").siblings().css("display","none"); } else {movehand;} }; movehand(); angle+=1; },10); });

    Read the article

  • How to parse (infinite) nested object notation?

    - by kyogron
    I am currently breaking my head about transforming this object hash: "food": { "healthy": { "fruits": ['apples', 'bananas', 'oranges'], "vegetables": ['salad', 'onions'] }, "unhealthy": { "fastFood": ['burgers', 'chicken', 'pizza'] } } to something like this: food:healthy:fruits:apples food:healthy:fruits:bananas food:healthy:fruits:oranges food:healthy:vegetables:salad food:healthy:vegetables:onions food:unhealthy:fastFood:burgers food:unhealthy:fastFood:chicken food:unhealthy:fastFood:pizza In theory it actually is just looping through the object while keeping track of the path and the end result. Unfortunately I do not know how I could loop down till I have done all nested. var path; var pointer; function loop(obj) { for (var propertyName in obj) { path = propertyName; pointer = obj[propertyName]; if (pointer typeof === 'object') { loop(pointer); } else { break; } } }; function parse(object) { var collection = []; }; There are two issues which play each out: If I use recurse programming it looses the state of the properties which are already parsed. If I do not use it I cannot parse infinite. Is there some idea how to handle this? Regards

    Read the article

  • How could I easily pack a directory to an ext4 loop partition image?

    - by Alvin Wong
    I would like to pack the content of a directory into an ext4 partition image easily, without mounting a loop device. Background: I am building a version of Android which will mount system partitions as a loop device for ARM. Though I can create those partition images by hand using loop devices, it is very troublesome. I want to use an sh script to automatically do the work, and without needing to loop mount the dd-created image and use cp -rp. The best is to directly pack the files into an image file. Question: Is there any simple command-line tools without needing loop mount and root permission that can pack files into an ext4 partition image?

    Read the article

  • Correct For Loop Design

    - by Yttrill
    What is the correct design for a for loop? Felix currently uses if len a > 0 do for var i in 0 upto len a - 1 do println a.[i]; done done which is inclusive of the upper bound. This is necessary to support the full range of values of a typical integer type. However the for loop shown does not support zero length arrays, hence the special test, nor will the subtraction of 1 work convincingly if the length of the array is equal to the number of integers. (I say convincingly because it may be that 0 - 1 = maxval: this is true in C for unsigned int, but are you sure it is true for unsigned char without thinking carefully about integral promotions?) The actual implementation of the for loop by my compiler does correctly handle 0 but this requires two tests to implement the loop: continue: if not (i <= bound) goto break body if i == bound goto break ++i goto continue break: Throw in the hand coded zero check in the array example and three tests are needed. If the loop were exclusive it would handle zero properly, avoiding the special test, but there'd be no way to express the upper bound of an array with maximum size. Note the C way of doing this: for(i=0; predicate(i); increment(i)) has the same problem. The predicate is tested after the increment, but the terminating increment is not universally valid! There is a general argument that a simple exclusive loop is enough: promote the index to a large type to prevent overflow, and assume no one will ever loop to the maximum value of this type.. but I'm not entirely convinced: if you promoted to C's size_t and looped from the second largest value to the largest you'd get an infinite loop!

    Read the article

  • google maps api v3 - loop through overlays - overlayview methods

    - by user317005
    how can i loop through an array within the overlayview class? $(document).ready(function() { var overlay; var myLatlng = new google.maps.LatLng(51.501743,-0.140461); var myOptions = { zoom: 13, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); OverlayTest.prototype = new google.maps.OverlayView(); var items = [ [51.501743,-0.140461], [51.506209,-0.146796], ]; for([loop])//loop through array { var latlng = new google.maps.LatLng(items[i][0], items[i][1]); var bounds = new google.maps.LatLngBounds(latlng); overlay = new OverlayTest(map, bounds); var element_id = 'map_' + i; function OverlayTest(map, bounds) { this.bounds_ = bounds; this.map_ = map; this.div_ = null; this.setMap(map); } OverlayTest.prototype.onAdd = function() { var div = ''; this.div_ = div; var panes = this.getPanes(); panes.mapPane.innerHTML = div; } OverlayTest.prototype.draw = function() { var overlayProjection = this.getProjection(); var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest()); var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast()); var div = document.getElementById(element_id); div.style.left = sw.x + 'px'; div.style.top = ne.y + 'px'; } } }); the above code doesn't work, but when i manually assign a lat/lng to the overlayview class it magically works (see below)?! $(document).ready(function() { var overlay; var myLatlng = new google.maps.LatLng(51.501743,-0.140461); var myOptions = { zoom: 13, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); OverlayTest.prototype = new google.maps.OverlayView(); var items = [ [51.501743,-0.140461], [51.506209,-0.146796], ]; var latlng = new google.maps.LatLng(51.506209,-0.146796);//manually assign lat/lng var bounds = new google.maps.LatLngBounds(latlng); overlay = new OverlayTest(map, bounds); function OverlayTest(map, bounds) { this.bounds_ = bounds; this.map_ = map; this.div_ = null; this.setMap(map); } OverlayTest.prototype.onAdd = function() { var div = ''; this.div_ = div; var panes = this.getPanes(); panes.mapPane.innerHTML = div; } OverlayTest.prototype.draw = function() { var overlayProjection = this.getProjection(); var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest()); var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast()); var div = document.getElementById('map_1'); div.style.left = sw.x + 'px'; div.style.top = ne.y + 'px'; } });

    Read the article

  • App crashes often in a for-loop

    - by Flocked
    Hello, my app crashes often in this for-loop: for (int a = 0; a <= 20; a++) { int b = arc4random() % [newsStories count]; NSString * foo = [[NSString alloc]initWithString:[[newsStories objectAtIndex: arc4random() % b]objectForKey:@"title"]]; foo = [foo stringByReplacingOccurrencesOfString:@"’" withString:@""]; foo = [[foo componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] componentsJoinedByString:@" "]; foo = [foo stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; textView.text = [textView.text stringByAppendingString:[NSString stringWithFormat:@"%@ ", foo]]; } The code changes a NSString from a NSDictionary and adds it into a textView. Sometimes it first crashes in the second time using the for-loop. What did I wrong?

    Read the article

  • Loop over DOMDocument

    - by Zoredache
    I am following the suggestion from this question Robust, Mature HTML Parser for PHP, about parsing html that may be malformed with DOMDocument. Is there any easy way to loop over the parsed document? So I would like to loop over html like this. $html='<ul> <li>value1</li> <li>value1</li> <li>value3</li> </ul> <p>hello world</p>'; $doc = new DOMDocument(); $doc->loadHTML($html); ??? foreach (??? as $node) { print $node->nodeName.':'.$node->nodeValue; } And get results somewhat like this. ul: li:value1 li:value2 li:value3 p:hello world

    Read the article

  • Add characters to month loop?

    - by JM4
    I currently have a php loop running exactly how I need it with proper validations (in both php and javascript) with one exception, if the month is less than 2 digits, (i.e. 1,2,3,4), I need for a '0' to appear before: 01 - January 02 - February ... 10 - October My code for the loop is currently: <select name="Month"> <option value="">Month</option> <?php for ($i=1; $i<=12; $i++) { echo "<option value='$i'"; if ($fields["Month"] == $i) echo " selected"; echo ">$i</option>"; } ?> </select> any ideas? Also note, this month date is being stored in session, not interested in printing to screen

    Read the article

  • How to Loop & rename MySQL table in Perl

    - by Nano HE
    Hi, Could you plesae teach me how to Loop & rename MySQL table in Perl. Thanks. my code snippet attached use strict; use warnings; use DBI; my $dbh = DBI->connect( 'DBI:mysql:database=dbdev;host=localhost', 'dbdev', 'dbdevpw', { RaiseError => 1, AutoCommit => 1 }, ); my $sql = RENAME TABLE old_table TO new_table; my $sth = $dbh->prepare($sql); while (<DATA>){ chomp; // How to implement the Rename all the old tables with the while loop. $sth->execute(); }

    Read the article

  • Good input validation loop using cin - C++

    - by Alex
    Hi there, I'm in my second OOP class, and my first class was taught in C#, so I'm new to C++ and currently I am practicing input validation using cin. So here's my question: Is this loop I constructed a pretty good way of validating input? Or is there a more common/accepted way of doing it? Thanks! Code: int taxableIncome; int error; // input validation loop do { error = 0; cout << "Please enter in your taxable income: "; cin >> taxableIncome; if (cin.fail()) { cout << "Please enter a valid integer" << endl; error = 1; cin.clear(); cin.ignore(80, '\n'); } }while(error == 1);

    Read the article

  • C - is it possible to decrement the max value of a for loop from within the for loop?

    - by hatorade
    for example: void decrement(int counter) { counter--; } int counter = 20; for (int i = 0; i < counter; i++) { for (int j = 0; j < counter, j++) { decrement(counter); } } ideally, what i'd like to see is the counter var being decremented every time the for loop is run, so that it runs fewer than 20 iterations. but gdb shows that within decrement() counter is decremented, but that going back to the for loop counter actually stays the same.

    Read the article

  • PHP - Loop thru recordset and fire event each n rows

    - by Luciano
    I'm looking for the right logic to loop thru a recordset and fire an event each n times. Searching on Google i've found some discussion on similar situations, but it seems that solutions don't fits my needs. Let's say i have a recordset of 22 rows. I want to loop thru each row and launch a function on the 4th, the 8th, the 12th and so on... Using the modulus operator as shown in this answer, if($i % 4 == 0), i get the event fired each 4 rows, but 22 its not a multiple of 4 so the event is fired till the 20th row and then nothing. Maybe i need to make a division counting rows in 'excess'? Since the recordset will be between 50 and 200 rows i think its not necessary run multiple query of 4 rows, am I wrong? Thanks in advance!

    Read the article

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