Search Results

Search found 8019 results on 321 pages for 'for in loop'.

Page 55/321 | < Previous Page | 51 52 53 54 55 56 57 58 59 60 61 62  | Next Page >

  • 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 add up amount of data from an external file in C# (Stream Reader)

    - by user2985995
    I'm new to this site, and pretty new to programming, at the moment I'm trying to display a count amount for the users names on my donation list, and then I also want to have a sum to work out the total amount of money the donation list contains, If someone could help me with creating a way to add up amount of donors on the donations.txt file that would be great help, I have no idea where to start, but so far this is my coding: string sName; double dAmount; string sTotalNames; double dAmountTotal; double dAmountAverage; using (StreamReader sr = new StreamReader("Donations.txt")) { while (sr.Peek() != -1) { sName = sr.ReadLine(); Console.WriteLine(sName); dAmount = Convert.ToDouble(sr.ReadLine()); Console.WriteLine(dAmount); } Console.WriteLine("Press any key to close"); Console.ReadKey(); }

    Read the article

  • Counting substring, while loop

    - by user1554786
    public class SubstringCount { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a word longer than 4 characters, and press q to quit"); int count = 0; while (scan.hasNextLine()) { System.out.println("Enter a word longer than 4 characters, and press q to quit"); String word = scan.next(); if (word.substring(0,4).equals("Stir")) { count++; System.out.println("Enter a word longer than 4 characters, and press q to quit"); scan.next(); } else if (word.equals("q")) { System.out.println("You have " + count + ("words with 'Stir' in them")); } else if (!word.substring(0,4).equals("Stir")) { System.out.println("Enter a word longer than 4 characters, and press q to quit"); scan.next(); } } } } Here I need to print how many words entered by the user contain the substring 'Stir.' However I'm not sure how to get this to work, or if I've done any of it right in the first place! Thanks for any help!

    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

  • jquery each to loop and animate

    - by medk
    I have some span tags: <span w="560"></span> <span w="340"></span> <span w="120"></span> With jQuery, I want to select EACH span, get the value inside its w attribute and animate it to that value + "px". I have a simple code that didn't work: $(document).ready(function(){ $('span').animate({width: $(this).attr('w') + 'px'}, 2000); }); Any Suggestions? Thanks.

    Read the article

  • Nested loop traversing arrays

    - by alecco
    There are 2 very big series of elements, the second 100 times bigger than the first. For each element of the first series, there are 0 or more elements on the second series. This can be traversed and processed with 2 nested loops. But the unpredictability of the amount of matching elements for each member of the first array makes things very, very slow. The actual processing of the 2nd series of elements involves logical and (&) and a population count. I couldn't find good optimizations using C but I am considering doing inline asm, doing rep* mov* or similar for each element of the first series and then doing the batch processing of the matching bytes of the second series, perhaps in buffers of 1MB or something. But the code would be get quite messy. Does anybody know of a better way? C preferred but x86 ASM OK too. Many thanks! Sample/demo code with simplified problem, first series are "people" and second series are "events", for clarity's sake. (the original problem is actually 100m and 10,000m entries!) #include <stdio.h> #include <stdint.h> #define PEOPLE 1000000 // 1m struct Person { uint8_t age; // Filtering condition uint8_t cnt; // Number of events for this person in E } P[PEOPLE]; // Each has 0 or more bytes with bit flags #define EVENTS 100000000 // 100m uint8_t P1[EVENTS]; // Property 1 flags uint8_t P2[EVENTS]; // Property 2 flags void init_arrays() { for (int i = 0; i < PEOPLE; i++) { // just some stuff P[i].age = i & 0x07; P[i].cnt = i % 220; // assert( sum < EVENTS ); } for (int i = 0; i < EVENTS; i++) { P1[i] = i % 7; // just some stuff P2[i] = i % 9; // just some other stuff } } int main(int argc, char *argv[]) { uint64_t sum = 0, fcur = 0; int age_filter = 7; // just some init_arrays(); // Init P, P1, P2 for (int64_t p = 0; p < PEOPLE ; p++) if (P[p].age < age_filter) for (int64_t e = 0; e < P[p].cnt ; e++, fcur++) sum += __builtin_popcount( P1[fcur] & P2[fcur] ); else fcur += P[p].cnt; // skip this person's events printf("(dummy %ld %ld)\n", sum, fcur ); return 0; } gcc -O5 -march=native -std=c99 test.c -o test

    Read the article

  • Actionscript 3.0 Get all instances of a class?

    - by Windbrand
    I got a ton of movieclips in a class. Is there a more efficient way to apply a function to every instance in the class other than this? var textArray:Array = [ interludes.interludeIntro.interludeBegin1, interludes.interludeIntro.interludeBegin2, interludes.interludeIntro.interludeBegin3, interludes.interludeIntro.interludeBegin4, interludes.interludeIntro.interludeBegin5, interludes.interludeIntro.interludeBegin6, interludes.interludeIntro.interludeBegin7, //... ... ... interludes.interludeIntro.interludeBegin15 ]; for each (var interludeText:MovieClip in interludeBeginText) { interludeText.alpha = 0 //clear all text first } Also for some reason this doesn't work: interludes.interludeIntro.alpha = 0; It permanently turns that class invisible, even if I try to make specific instances visible later with: interludes.interludeIntro.interludeBegin1.alpha = 1; I have NO idea why the above doesn't work. I want to turn every single instance in the class interludeIntro invisible, but I want to turn specific instances visible later. (btw I have no idea how to insert code on this website, pressing "code" doesn't do anything, so pardon the bad formatting)

    Read the article

  • A loop (while/foreach) with "offset" wrapping and

    - by DarkGhostHunter
    After applying what wrapping objects using math operator, I just tought it will be over. But no. By far. <?php $faces= array( 1 => '<div class="block">happy</div>', 2 => '<div class="block">sad</div>', (sic) 21 => '<div class="block">angry</div>' ); $i = 1; foreach ($faces as $face) { echo $face; if ($i == 3) echo '<div class="block">This is and ad</div>'; if ($i % 3 == 0) { echo "<br />"; // or some other wrapping thing } $i++; } ?> In the code I have to put and ad after the second one, becoming by that the third object. And then wrap the three all in a <div class="row"> (a br after won't work out by design reasons). I thought I will going back to applying a switch, but if somebody put more elements in the array that the switch can properly wrap, the last two remaining elements are wrapped openly. Can i add the "ad" to the array in the third position? That would make things simplier, only leaving me with guessing how to wrap the first and the third, the fourth and the sixth, an so on.

    Read the article

  • simple for loop not running

    - by NativeCoder
    for ( var i:int = 0 ; i < 1; i++) { for ( var j:int = 0 ; j < 1; j++) { if (shape[j][i] == 0 ) { pencil.graphics.beginFill(0); pencil.graphics.drawRect(10,10,5,5); pencil.graphics.endFill(); } } } i am trying to run this code where shape is an array 2*2 gives an error ReferenceError: Error #1069: Property 0 not found on Number and there is no default value. at Main() need help

    Read the article

  • Using varible in re.match in python

    - by screwuphead
    I am trying to create an array of things to match in a description line. So I cant ignore them later on in my script. Below is a sample script that I have been working on, on the side. Basically I am trying to take a bunch of strings and match it against a bunch of other strings. AKA: asdf or asfs or wrtw in string = true continue with script if not print this. import re ignorelist = ['^test', '(.*)set'] def guess(a): for ignore in ignorelist: if re.match(ignore, a): return('LOSE!') else: return('WIN!') a = raw_input('Take a guess: ') print guess(a) Thanks

    Read the article

  • getline with ints C++

    - by Mdjon26
    I have a file 0 3 2 1 2 3 4 5 6 6 8 1 Where the first number for each line is the row, the second number is the column, and the third number is the data contained in that row, column. This will be a given [8][8] array so I have already initialized everything to 0, but how can I store each of these data values? For example, I want [0][3] =2 and [1][2] = 3. I would like to keep track of the line on which I found that row, col, and data value. So, how can I correctly insert these values into my 2-D array? int rowcol[8][8]; for (int i=0; i < 9; i++) for (int j=0; j < 9; j++) { rowcol[i][j] =0; } ifstream myfile; int nums; myfile.open(text.c_str()); while (!myfile.eof()) { myfile >> nums; numbers.push_back(nums); } for (int i=0; i < numbers.size(); i++) { //Not sure what the best approach here would be and I'm not even sure if I should have done a vector... }

    Read the article

  • Running a loop (such as one for a mock webserver) within a thread

    - by bob c
    I'm trying to run a mock webserver within a thread within a class. I've tried passing the class' @server property to the thread block but as soon as I try to do server.accept the thread stops. Is there some way to make this work? I want to basically be able to run a webserver off of this script while still taking user input via stdin.gets. Is this possible? class Server def initialize() @server = TCPServer.new(8080) end def run() @thread = Thread.new(@server) { |server| while true newsock = server.accept puts "some stuff after accept!" next if !newsock # some other stuff end } end end def processCommand() # some user commands here end test = Server.new while true do processCommand(STDIN.gets) end In the above sample, the thread dies on server.accept

    Read the article

  • add objects with different name through for loop

    - by Gandalf StormCrow
    What is the best way to do the following: List<MyObject> list = new LinkedList<MyObject>(); for(int i=0; i<30;i++) { MyObject o1 = new MyObject(); list.add(o1); } But the things is I don't wanna create objects with same name, I wanna create them with different name like o1,o2,o3,o4,o5,o6,o7,o8,o9,o10 and I wanna add each to the list. What is the best way to do this ?

    Read the article

  • Parallelizing for loop

    - by vman049
    I have MATLAB code which I'm trying to parallelize with a simple change from "for" to "parfor." I'm unable to do so because of an error I'm receiving on the variable "votes" which states: Valid indices for 'votes' are restricted in PARFOR loops. Explanation: For MATLAB to execute parfor loops efficiently, the amount of data sent to the MATLAB workers must be minimal. One of the ways MATLAB achieves this is by restricting the way variables can be indexed in parfor iterations. The indicated variable is indexed in a way that is incompatible with parfor. Suggested Action: Fix the indexing. For a description of the indexing restrictions, see “Sliced Variables” in the Parallel Computing Toolbox documentation. Below is my code: votes = zeros(num_layers, size(spikes, 1), size(SVMs_layer1, 1)); predDir = zeros(size(spikes, 1), 1); chronProb = zeros([num_layers, size(chronDists)]); for i = 1:num_layers switch i case 1 B = B1; k_elem_temp = k_elem1; rest_elem_temp = rest_elem1; case 2 B = B2; k_elem_temp = k_elem2; rest_elem_temp = rest_elem2; case 3 B = B3; k_elem_temp = k_elem3; rest_elem_temp = rest_elem3; end for j = 1:length(chronPred) if chronDists(i, j, :) ~= 0 parfor k = 1:8 chronProb(i, j, k) = logistic(B{k}(1) + chronDists(i, j, k).*(B{k}(2))); votes(i, j, k_elem_temp(k, :)) = votes(i, j, k_elem_temp(k, :)) + chronProb(i, j, k)/num_k(i)/num_layers; votes(i, j, rest_elem_temp(k, :)) = votes(i, j, rest_elem_temp(k, :)) + (1 - chronProb(i, j, k))/num_rest(i)/num_layers; end end end end Do you have any suggestions as to how I could adjust my code so that it runs in parallel? Thank you!

    Read the article

  • How do i loop an ajax request (using jquery) and jsp

    - by Mrshll187
    <script> //when page is ready do the following $(document).ready(function() { //set interval of refresh setInterval(doAjaxMethod, 1000); }); function doAjaxMethod(id) { $.ajax({ url: "getStatus/"+id, dataType: "json", success: function(json) { $('#ajaxStatus').html(json.status); } }); </script> <% //How can I do something like this int n = object.size(); for(int i=0; i<n; i++) { doAjaxMethod(object.getId()); } %> <div id=ajaxStatus> status updates here </div>

    Read the article

  • Java loop and increment problem

    - by user552961
    Can any one tell me what is the problem in my program? String a[],b[]; int c[] = new int[b.length]; for (int j = 0; j < a.length; j++) { for (int k = 0; k < b.length; k++) { if (b[k].equals(a[j])) { c[k]++; } else { c[k] = 0; } } } I have thousands of words stored in a HashMap. Now I want to check in every file that how many time one word occurred from allWords. Can you point out mistake in my program or give me your idea that how I can do it?

    Read the article

  • Using Jquery 1.8.0 return false is not breaking an each() loop

    - by user1879729
    Here is the script I am using. $('.row').each(function(){ $(this).each(function(){ if($(this).find('.name').val()==""){ $(this).find('.name').val(data.name); $(this).find('.autonomy').val(data.autonomy); $(this).find('.purpose').val(data.purpose); $(this).find('.flow').val(data.flow); $(this).find('.relatedness').val(data.relatedness); $(this).find('.challenge').val(data.challenge); $(this).find('.mastery').val(data.mastery); $(this).find('.colour').val(data.colour); done=true; } if(done==true){ alert("here"); return false; } }); }); It just seems to totally ignore the return false and I can't seem to work out why!

    Read the article

  • Not really a quaestion...but i need help

    - by Dan F.
    I have to make a process in Oracle/PLSQL.....i have to verify that the interval of time between start_date and end_date from a new row that i create must not intersect other start_dates and end_dates from other rows. Now I need to check each row for that condition and if it doesn't correspond the repetitive instruction should stop and after that to display a message such as "The interval of time given is not correct". I don't know how to make repetitive instructions in Oracle/PLSQL and I would appreciate if you would help me.

    Read the article

  • Loop function works first time, not second time

    - by user1483101
    I'm creating a parsing program to look for certain strings in a a text file and count them. However, I'm having some trouble with one spot. def callbrowse(): filename = tkFileDialog.askopenfilename(filetypes = (("Text files", "*.txt"),("HTML files", ".html;*.htm"),("All files", "*.*"))) print filename try: global filex global writefile filex = open(filename, 'r') print "Success!!" print filename except: print "Failed to open file" ######This returns the correct count only the first time it is run. The next time it ######returns 0. If the browse button is clicked again, then this function returns the ######correct count again. def count_errors(error_name): count = 0 for line in filex: if error_name == "CPU > 79%": stringparse = "Utilization is above" elif error_name == "Stuck touchscreen": stringparse = "Stuck touchscreen" if re.match("(.*)" + "Utilization is above" + "(.*)",line): count = count + 1 return count Thanks for any help. I can't seem to get this to work right.

    Read the article

  • MySQL Table Loop using PHP

    - by JM4
    I have an online form which collects consumer data and stores in a dedicated MySQL database. In some instances, data is passed in the URL under the "RefID" variable which is also stored in the database and attached to each registration. I use the 'mysql_num_rows ($result)' to fetch all agent details on another page but this only returns ALL available details. My goal is as follows: GOAL I want to create an HTML table in which rows are automatically generated based on the list of all registrations on my site. A new row is created IF and ONLY IF a unique RefID is present on that particular record. In the event the field is NULL, it is reported on a single line. In short, the HTML table could look something like this: RefID - Number of Enrollments abc123 - 10 baseball - 11 twonk - 7 NULL - 33 Where abc123 is a particular RefID and 10 is the number of times that RefID appears in the DB. If a new registration comes in with RefID = "horses", a new row is created, showing "horses - 1". The HTML table will be viewable by account administrators needing to see the number of enrollments for a particular RefID (which they won't know ahead of time). Anybody have any suggestions?

    Read the article

  • How to loop X times in Django?

    - by Mark
    I have user reviews on my site. Each review has a rating of 1-5 stars. I want to print that many stars. How do I do it? I only see {% for X in Y %} which lets you iterate over a list, but not a certain number of times.

    Read the article

  • PHP Math issue with negatives [closed]

    - by user1269625
    Possible Duplicate: PHP negatives keep adding I have this code here.... $remaining = 0; foreach($array as $value=>$row){ $remaining = $remaining + $row['remainingbalance']; } What its doing is that it is going through all the remaining balances in the array which are -51.75 and -17.85 with the code above I get -69.60 which is correct. But I am wondering how when its two negatives if they could subtract? Is that possible? I tried this $remaining = 0; foreach($clientArrayInvoice as $value=>$row){ $remaining = $remaining + abs($row['remainingbalance']); } but it gives me 69.60 without the negative. Anyone got any ideas? my goal is to take -51.75 and -17.85 and come up with -33.90 only when its a negative to do subtract. otherwise add

    Read the article

  • Getting key column in loop + XSLT

    - by rajcog
    Hi, I need a help on getting primary key values repeated times from the xml.Here is the xml file. the required output is KeycolumnName,Columnname customer_id,customer_id customer_id,customer_name customer_id,customer_address Can anyone help me on this?

    Read the article

  • Persisting objects to a database using a loop

    - by ChaoticLoki
    I have a form that returns multiple values and each value I would like to store in a database, I created a test form for this purpose <form method="post" action="{{ path('submit_exercise', {'page': 1}) }}"> <input type="hidden" name="answers[]" value="Answer 1" "/> <input type="hidden" name="answers[]" value="Answer 2" "/> <input type="hidden" name="answers[]" value="Answer 3" "/> <input type="hidden" name="answers[]" value="Answer 4" "/> <input type="hidden" name="answers[]" value="Answer 5" "/> <input type="hidden" name="answers[]" value="Answer 6" "/> <input type="hidden" name="answers[]" value="Answer 7" "/> <input type="submit" name="submit" /> </form> </body> </html> My submit answers Action is currently written like so. public function submitAnswersAction($page) { //get submitted data $data = $this->get('request')->request->all(); $answers = $data['answers']; //get student ID $user = $this->get('security.context')->getToken()->getUser(); $studentID = $user->getId(); //Get Current time $currentTime = new \DateTime(date("Y-m-d H:m:s")); //var_dump($answers); //var_dump($studentID); //var_dump($currentTime); for($index = 0; $index < count($answers); $index++) { /*echo "Question ". ($index + 1) ."<br />"; echo "Student ID: ". $studentID."<br />"; echo "Page Number: $page <br />"; echo "Answer: $answers[$index]"."<br />"; echo "<br />";*/ $studentAnswer = new StudentAnswer(); $studentAnswer->setStudentID($studentID); $studentAnswer->setPageID($page); $studentAnswer->setQuestionID($index+1); $studentAnswer->setAnswer($answers[$index]); $studentAnswer->setDateCreated($currentTime); $studentAnswer->setReadStatus(0); $database = $this->getDoctrine()->getManager(); $database->persist($studentAnswer); $database->flush(); } return new Response('Answers saved for Student: '.$user->getFullName().' for page: '.$page); When I do a var_dump everything seems to be associated correctly, meaning that the answers array is populated with the right data and so is every other variable, my problem is actually persisting it to the database. when run it returns with this error which seems to me like it doesn't know what variables to put into the row. An exception occurred while executing 'INSERT INTO Student_Answer (student_id, page_id, question_id, answer, read, date_created) VALUES (?, ?, ?, ?, ?, ?)' with params {"1":2,"2":"1","3":1,"4":"Answer 1","5":0,"6":"2012-12-11 12:12:20"}: Any help would be greatly appreciated as this is a personal project to help me try and understand web development a bit more.

    Read the article

< Previous Page | 51 52 53 54 55 56 57 58 59 60 61 62  | Next Page >