Search Results

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

Page 21/68 | < Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >

  • VB.NET 2008 Application crashing during Do Loop

    - by RedHaze
    I am writing an application to compare each item on listbox1 to all items on listbox2. If the item is found, then remove it from both lists. The goal is to only have the items that were not found remain on both lists. The problem is, the application just hangs and I never get any results. I looked at my code several times and I cannot figure out what's going on (programming noob I know...). Can anybody help me with this? Code Snippet: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim a As String Dim b As String Dim y As String For i As Integer = 0 To ListBox1.Items.Count - 1 a = ListBox1.Items(i) y = 1 Do While y = 1 For x As Integer = 0 To ListBox2.Items.Count - 1 b = ListBox2.Items(x) Dim res As Int16 = String.Compare(a, b) If res = 0 Then y = 0 ListBox2.Items.Remove(i) ListBox2.Items.Remove(x) ElseIf x = ListBox1.Items.Count Then Exit Do End If Next Loop Next End Sub

    Read the article

  • Help with simple javascript loop

    - by Gabriel
    Hello, I have a simple javascript that I'd like to loop for multiple elements. Here's my code: <script type='text/javascript'> for(i = 1; i < 100; i++) { $('#link'+i).click(function() { $('#container').removeClass(); $('#container').addClass('templateid'+i); }); } </script> What I'd like to achieve is the same addClass function for multiple id's (e.g. link2, link3, link4), with the corresponding class (e.g. template2, template3, template4). Any help would be hugely appreciated! For reference, an individual call like this one, does work, so I don't see why the loop above doesn't function the same: <script type='text/javascript'> $('#link2').click(function() { $('#container').removeClass(); $('#container').addClass('templateid2'); }); </script>

    Read the article

  • Moving x,y position of all array objects every frame in actionscript 3?

    - by Dylan Gallardo
    I have my code setup so that I have an movieclip in my library a class called "block" being duplicated multiple times and added into an array like this: function makeblock(e:Event){ newblock=new block; newblock.x=10; newblock.y=10; addChild(newblock); myarray[counter] = newblock; //adds a newblock object into array counter += 1; } Then I have a loop with a currently primitive way of handling my problem: stage.addEventListener(Event.ENTER_FRAME, gameloop); function gameloop(evt:Event):void { if (moveright==true){ myarray[0].x += 5; myarray[1].x += 5; myarray[2].x += 5 -(and so on)- My question is how can I change x,y values every frame for new objects duplicated into the array, along with the previous ones that were added. Of course with a more elegant way than writing it out myself... array[0].x += 5, array[1], array[2], array[3] etc. Ideally I would like this to go up to 500 or more array objects for one array so obviously I don't want to be writing it out individually haha, I also need it to be consistent with performance so using a for loop or something to loop through the whole array and move each x += 5 wouldn't work would it? Anyway, if anyone has any ideas that'd be great!

    Read the article

  • PHP while loop, table row

    - by Elliott
    Hi, I'm trying to loop through a database and output data into a div, if there are 3 divs horizontally accross it will the start a new tr until it reaches another 3 etc. It is currently outputted like : [] [] [] [] [] [] Currently I have it working when it reaches 3 it starts a new row, but I don't know how I can only echo a new tr once? As it creates a new table row each time. echo '<table><tr>'; while ($result) { $i ++; if ($i&3) { echo '<td> <div>Row Data</div> </td>'; } else { echo '<tr> <td> <div>Row Data</div> </td></tr>'; } } echo '</tr></table>'; The $result variable is the recordset from my sql query, everything works fine I just don't know how to only create a new table row once? Thanks

    Read the article

  • PHP: Display comma after each element except the last. Using 'for' statement and no 'implode/explode

    - by Jonathan
    hi, so I have this simple for loop to echo an array: for ($i = 0; $i < count($director); $i++) { echo '<a href="person.php?id='.$director[$i]["id"].'">'.$director[$i]["name"].'</a>'; } The problem here is that when more than one element is in the array then I get everything echoed without any space between. I want to separate each element with a comma except the last one. I cant use 'implode' so I'm looking for another solution... Anyone?

    Read the article

  • Loop each x elements

    - by Cimm
    What's the beste way to show a list with 20 images in rows of 5? Or, in other words, how do I clean up this ugly snippet? <div class="row"> <% @images.each_with_index do |image, index| %> <%= image_tag image.url %> <% if index != 0 && index % 5 == 0 %> </div><div class="row"> <% end %> <% end %> </div>

    Read the article

  • Python for loop question

    - by Joe Dunk
    I was wondering how to achieve the following in python: for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through I tried this with no luck. for i in range(whatever): if cond... : i += 1

    Read the article

  • ruby looping question

    - by jonepatr
    Hello! I want to make a loop on a variable that can be altered inside of the loop. first_var.sort.each do |first_id, first_value| second_var.sort.each do |second_id, second_value_value| difference = first_value - second_value if difference >= 0 second_var.delete(second_id) else second_var[second_id] += first_value if second_var[second_id] == 0 second_var.delete(second_id) end first_var.delete(first_id) end end end How do I do this, because this doesn't work?

    Read the article

  • only return random number when it is unique

    - by phil
    My brain is melting today and i cannot think how to do this simple bit of code. numberList is a string of numbers seperated by commas like '2, 34, 10' etc.. when i request a random number i need to check if the string has the number, if it does i want to keep requesting a random number until the random number is definitely not in the string. i cant think what kind of loop i would do to get this to work: Random r = new Random(); public int RandomPos(int max) { int i; do { i = r.Next(max) + 1; } while (!numberList.Contains(i.ToString())); return i; }

    Read the article

  • VB looping complication

    - by user1819469
    I have to come up with a program that shifts names in a text box a random amount of times. I have gotten everything up to the point where the names shifts a random amount of times. It only shifts its once, but my messagebox appears through the code as many times as the names should be shifting once i click ok. Does anyone know why the loop is not working for the name shifts. I was thinking maybe the messagebox needs to control the loop, but I have searched endlessly and cannot find how that would be done. Any suggestions or referrals to other sites would be nice thanks. My code is below. Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim RandomNumber As Integer Dim min, max As Integer Dim temp, temp2, temp3, temp4, temp5, temp6 As String Dim i As Integer min = 3 max = 11 Randomize() RandomNumber = Int((max - min + 1) * Rnd() + min) temp = n1.Text temp2 = n2.Text temp3 = n3.Text temp4 = n4.Text temp5 = n5.Text temp6 = n6.Text For i = 0 To RandomNumber - 1 n1.Text = temp6 n2.Text = temp n3.Text = temp2 n4.Text = temp3 n5.Text = temp4 n6.Text = temp5 MessageBox.Show("Shift " & i & " of " & RandomNumber & " complete") Next End Sub End Class

    Read the article

  • Objective-C vs JavaScript loop performance

    - by micadelli
    I have a PhoneGap mobile application that I need to generate an array of match combinations. In JavaScript side, the code hanged pretty soon when the array of which the combinations are generated from got a bit bigger. So, I thought I'll make a plugin to generate the combinations, passing the array of javascript objects to native side and loop it there. To my surprise the following codes executes in 150 ms (JavaScript) whereas in native side (Objective-C) it takes ~1000 ms. Does anyone know any tips for speeding up those executing times? When players exceeds 10, i.e. the length of the array of teams equals 252 it really gets slow. Those execution times mentioned above are for 10 players / 252 teams. Here's the JavaScript code: for (i = 0; i < GAME.teams.length; i += 1) { for (j = i + 1; j < GAME.teams.length; j += 1) { t1 = GAME.teams[i]; t2 = GAME.teams[j]; if ((t1.mask & t2.mask) === 0) { GAME.matches.push({ Team1: t1, Team2: t2 }); } } } ... and here's the native code: NSArray *teams = [[NSArray alloc] initWithArray: [options objectForKey:@"teams"]]; NSMutableArray *t = [[NSMutableArray alloc] init]; int mask_t1; int mask_t2; for (NSInteger i = 0; i < [teams count]; i++) { for (NSInteger j = i + 1; j < [teams count]; j++) { mask_t1 = [[[teams objectAtIndex:i] objectForKey:@"mask"] intValue]; mask_t2 = [[[teams objectAtIndex:j] objectForKey:@"mask"] intValue]; if ((mask_t1 & mask_t2) == 0) { [t insertObject:[teams objectAtIndex:i] atIndex:0]; [t insertObject:[teams objectAtIndex:j] atIndex:1]; /* NSArray *newCombination = [[NSArray alloc] initWithObjects: [teams objectAtIndex:i], [teams objectAtIndex:j], nil]; */ [combinations addObject:t]; } } } ... the array in question (GAME.teams) looks like this: { count = 2; full = 1; list = ( { index = 0; mask = 1; name = A; score = 0; }, { index = 1; mask = 2; name = B; score = 0; } ); mask = 3; name = A; }, { count = 2; full = 1; list = ( { index = 0; mask = 1; name = A; score = 0; }, { index = 2; mask = 4; name = C; score = 0; } ); mask = 5; name = A; },

    Read the article

  • JQuery: loop through elements with more than one css class name that share only the first class name

    - by omaether
    Hello, I'm trying to use JQuery to loop through several div's with more than one class name, that all have the same first css class name and each one has a different second class name, e.g. <div class="maintext blue"> </div> <div class="maintext purple"> </div> <div class="maintext chartreuse"> </div> <div class="maintext puce"> </div> <div class="maintext lime"> </div> In JQuery I have tried $(".mainText").each(function (i) $(".mainText.*").each(function (i) $(".mainText" *).each(function (i) $(".mainText .*").each(function (i) But it will not select any of the divs with class="mainText ..." thanks for considering the question.

    Read the article

  • Java - Can i have a faster performance for this loop ?

    - by Brad
    I am reading a book and deleting a number of words from it. My problem is that the process takes long time, and i want to make its performance better(Less time), example : Vector<String> pages = new Vector<String>(); // Contains about 1500 page, each page has about 1000 words. Vector<String> wordsToDelete = new Vector<String>(); // Contains about 50000 words. for( String page: pages ) { String pageInLowCase = page.toLowerCase(); for( String wordToDelete: wordsToDelete ) { if( pageInLowCase.contains( wordToDelete ) ) page = page.replaceAll( "(?i)\\b" + wordToDelete + "\\b" , "" ); } // Do some staff with the final page that does not take much time. } This code takes around 3 minutes to execute. If i skipped the loop of replaceAll(...) i can save more than 2 minutes. So is there a way to do the same loop with a faster performance ?

    Read the article

  • More compact way to do this?

    - by Macha
    I have a couple of functions that loop around the surrounding cells of a cell. The grid is contained inside an array. In my code, I have checks to make sure it's not one of the edge cells, as checking an undefined cell causes an error. As such, I have code like this: if(x > 0) { var firstX = x - 1; } else { var firstX = x; } if(x < 199) { var lastX = x + 1; } else { var lastX = x; } if(y > 0) { var firstY = y - 1; } else { var firstY = y; } if(y < 199) { var lastY = y + 1; } else { var lastY = y; } A lot of lines of code to do very little. Is there a more elegant way to do this?

    Read the article

  • C++ - my loop keeps on adding up to 0

    - by user1756913
    so far here's my code #include <iostream> using namespace std; int main () { int num1 = 0; int num2 = 0; int sum = 0; for(num2 = num1; num1 <= num2; num1 +=2) sum += num1; num1 = num1 / 2 == 0? num1 : num1 + 1; num2 = num2 / 2 == 0? num2 : num2 - 1; cout << "Enter the First Number:" << endl; cin >> num1; cout << "Enter the Second Number:" << endl; cin >> num2; cout << "Total Sum: " << sum << endl; } //end for but the sum keeps on adding up to 0 :/ here's the problem. Create a program that displays the sum of the even numbers between and including two numbers entered by the user. In other words, if the user enters an even number, that number should be included in the sum. For example, if the user enters the integers 2 and 7, the sum is 12 (2 + 4 + 6). If the user enters the integers 2 and 8, the sum is 20 (2 + 4 + 6 + 8 ). Display an error message if the first integer entered by the user is greater than the second integer.

    Read the article

  • How to get the class of an input inside a jQuery each loop?

    - by Paul Atkins
    Hi, I have function which appends inputs inside a list item when a link is clicked. I then loop through these inputs using an each loop using the code below. It is working correctly as shown, however instead of using field.name I want to use the class of the input as the array key but when i try to do this the class is shown as undefined. Here is the code I am currently using: var values = {}; $.each($('li :input').serializeArray(), function(i, field) { values[field.name] = field.value; }); Here is the code I have inside the list item once I have appended the hidden inputs using jQuery append: <li><input type="hidden" name="group" class="group" value="2"/><input type="hidden" name="condition" class="condition" value="isany"/><input type="hidden" name="value" class="value" value="1,2"/></li> I can get the name attribute fine but class is always undefined. Could anybody help with this?

    Read the article

  • Java: "cannot find symbol" error of a String[] defined within a while-loop

    - by David
    Here's the relevant code: public static String[] runTeams (String CPUcolor) { boolean z = false ; //String[] a = new String[6] ; boolean CPU = false ; while (z == false) { while (CPU==false) { String[] a = assignTeams () ; printOrder (a) ; for (int i = 1; i<a.length; i++) { if (a[i].equals(CPUcolor)) CPU = true ; } if (CPU==false) { System.out.println ("ERROR YOU NEED TO INCLUDE THE COLOR OF THE CPU IN THE TURN ORDER") ; } } System.out.println ("is this turn order correct? (Y/N)") ; String s = getIns () ; while (!((s.equals ("y")) || (s.equals ("Y")) || (s.equals ("n")) || (s.equals ("N")))) { System.out.println ("try again") ; s = getIns () ; } if (s.equals ("y") || s.equals ("Y") ) z = true ; } return a ; } the error i get is: Risk.java:416: cannot find symbol symbol : variable a location: class Risk return a ; ^ Why did i get this error? It seems that a is clearly defined in the line String[] a = assignTeams () ; and if anything is used by the lineprintOrder (a) ;` it seems to me that if the symbol a really couldn't be found then the compiler should blow up there and not at the return statment. (also the method assignTeams returns an array of Strings.)

    Read the article

  • How to iterate over numerically named object properties

    - by Scott Schluer
    So I have a horribly designed class that I can't change that has properties like this: object.Color1 object.Color2 object.Color3 etc... How can I iterate through those with a for loop. In other words, something like this: for (int i = 0; i <= 40; i++) { string PropertyName = "Color" + i; if (object.PropertyName != "") { // do something } } Obviously this code wouldn't work but it gives you an idea of what I'm after. I have to do some processing on each property and I don't want to repeat my code 40 times. :) A loop would be perfect, I'm just not sure how to create the name of the property on the fly.

    Read the article

  • What is wrong with this php loop?

    - by Mark R
    I made a loop but it doesn't work. here's what I did: <?php if(is_tree('4')) { ?> <?php $show_after_p = 2; $content = apply_filters('the_content', $post->post_content); if(substr_count($content, '<p>') > $show_after_p) { $contents = explode("</p>", $content); $p_count = 1; foreach($contents as $content) { echo $content; if($p_count == $show_after_p) { ?> YOUR AD CODE GOES HERE < ? } echo "</p>"; $p_count++; } } ?> <?php else : ?> <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?> <?php endif; } ?> I need to make it work but don't know how. I'm guessing it's a simple syntax error I'm not seeing?

    Read the article

  • Java loop to collect the second and third elements every three in an array

    - by mhollander38
    I have a file with data in the form timestamp, coordinate, coordinate, seperated by spaces, as here; 14:25:01.215 370.0 333.0 I need to loop through and add the coordinates only to an array. The data from the file is read in and put into as String[] called info, from split(" "). I have two problems, I think the end of the file has a extra " " which I need to lose appropriately and I also want confirmation/suggestions of my loop, at the moment I am getting sporadic out of bounds exceptions. My loop is as follows; String[] info; info = dataHolder.split(" "); ArrayList<String> coOrds1 = new ArrayList<String>(); for (int counter = 0; counter < info.length; counter = counter+3) { coOrds1.add(info[counter+1]); coOrds1.add(info[counter+2]); } Help and suggestions appreciated. The text file is here but the class receives in a UDP packet from another class so I am unsure if this potentially adds " " at the end or not.

    Read the article

  • Add inputs to more than one row in a structure array in matlab

    - by ZaZu
    Hi there, I would like to know how can I get certain inputs and put them in more than one row in the structure ... I basically want a structure that updates one input per row in ever loop. The loop is looped 30 times, so I want to have 30 rows and 2 columns ( x and y columns) I have this code : For N=1:30 . . . Binary = bwlabel(blacknwhite); s = regionprops(Binary,'centroid'); centroids = cat(1, s.Centroid); hold(imgca,'on') plot(imgca,centroids(1,1), centroids(1,2),'r*') . . . end I dont think this does what I want ... only the first row is updated in my loop .. So how can I create this structure ? If you want more info please tell me and I will update it right away. Thanks !

    Read the article

  • Refactoring a nested loop

    - by user3517441
    I have the following code which I use a lot of times in the class. for (int i = 0; i < someList.size(); i++) { for (int j = 0; j < someList.size(); j++) { if (i != j) { someList.get(i).sendMessageTo(someList.get(j))); //variable action } } } The purpose of the loop is to make each element in the List to send a message (or perform another action) to every element in the list except itself. Is there any way I can create a helper method so I don't have to repeat the loop code. I want to be able to state the variable action and call the helper method. Thanks.

    Read the article

  • How to get the next row from the Database table?

    - by Parth
    How to get the next row from the Database table? Such that the row might be incremented row that is if structure has a field called "id" then the row can be id++ or very next incremented row, but it may also b any other id containing row (NOT VERY NEXT) , (because the ids could be deleted from the table). the point of id I am talking about is It could be 1,2,3,4.... or it could be 1,6,7,8,23.. so on.... Please help for fetching the next row in the for loop to get it checked.

    Read the article

  • Loop through different sets of unique permutations

    - by user558610
    Hi I'm having a hard time getting started to layout code for this problem. I have a fixed amount of random numbers, in this case 8 numbers. R[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; That are going to be placed in 3 sets of numbers, with the only constraint that each set contain minimum one value, and each value can only be used once. For example: R1[] = { 1, 4 } R2[] = { 2, 8, 5, 6 } R3[] = { 7, 4 } I need to loop through all possible combinations of a set R1, R2, R3. Order is not important, so if the above example happened, I don't need R1[] = { 4, 1 } R2[] = { 2, 8, 5, 6 } R3[] = { 7, 4 } NOR R1[] = { 2, 8, 5, 6 } R2[] = { 7, 4 } R3[] = { 1, 4 } What is a good method?

    Read the article

  • Retrieving the value of a concatenated variable within a Java FOR loop

    - by Rajat
    I have been using this "logic" in C++ and VB with success, but am tied up in Java... Simply put, public void DataProviderExample(String user, String pwd, String no_of_links, String link1, String link2, String link3) { for (int i=1;i<=no_of_links;i++) { String link = "link"+i; System.out.println(link); } Now, if the variables link1, link2 and link3 have a value of "X", "Y" and "Z" respectively, upon running this program, I get the following output - link1 link2 link3 What I want is - X Y Z Any ideas?

    Read the article

< Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >