Search Results

Search found 12044 results on 482 pages for 'foreach loop'.

Page 64/482 | < Previous Page | 60 61 62 63 64 65 66 67 68 69 70 71  | Next Page >

  • 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

  • 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

  • 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

  • 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

  • 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

  • C# return and display syntax issue

    - by thatdude
    I am having trouble passing the return value from TheMethod() to Main and displaying the word if the if statement is passed as true. I have thought of two ways of doing this, neither has worked but I think I am missing synatx. Using a return ?; non void method and then displaying the returned value. Using a void method and actually writing out(example below) So yes I am new at this, however I have made so many iterations everything is blending together and I have forgot what I have tried. Any help on the syntax be great for either of these ways. Basically I need it to iterate numbers 1,2,3,4 and depending on if the current iteration matches an expression in the if statements it will display a word. Example: if (3 = i) { Console.WriteLine("Word"); } Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Proj5 { class Program { int i = 0; static void Main(int i) { for (i = 0; i < 101; i++) { Console.WriteLine("test"); } } string TheMethod(int i) { string f = "Word1"; string b = "Word2"; if (i == 3) { return f; } if (i == 5) { return b; } if (0 == (i % 3)) { return f; } if (0 == i % 5) { return b; } else { return b; } } } }

    Read the article

  • linked list printing using while loop and combining like terms

    - by C Z
    i have a problem printing out my linked list. My program asks the user to enter many different coefficients and degrees and makes it a polynomial and using mergesort it sorts it and then prints it, now i want to combine like terms and i have a problem doing so. thats part of my function that i don't know what is wrong with it: Term* p; p=poly; if (p==0) cout<<"---empty list---"; while(p !=0) if (p->coef==(p->next)->coef){ cout<<(p->deg)+((p->next)->deg)<<"x^"<<(p->coef)<<endl; p=p->next;} if (p->coef !=(p->next)->coef){ cout<<p->deg<<"x"<<p->coef<<"+"; p=p->next;} cout<<endl; } and thats my struct: struct Term { int deg; float coef; Term *next; }; typedef Term* Poly;

    Read the article

  • Running C++ functions simultaneously

    - by user2974881
    My code is similar to the following: int main() { values(); } int values() { if (condition) { 'code' } else if (condition) { 'code' } else { 'code' } motors(); } int motors() { 'code' } motors() needs values from values() to run. What could I do so that values() and motors() run simultaneously, side by side, and keep running until the user exits out of the program?

    Read the article

  • Async Task in a loop

    - by Ankuj
    How does one create an AsyncTask which keeps running itself after a fixed interval of time. For eg. get data from server every 5 minutes and give notification to caller thread that it has received the data. I searched on the forum but could not find much. What I have gathered so far is that 1) A UI thread will call AsyncTask 2) onPrExecute for UI thread access before executing 3) OnPostExecute for UI thread access after executing I dont need to show any progress update to the user. Also, the task will be destroyed when the app closes. Any tutorial for this will he helpful

    Read the article

  • Change value of adjacent vertices and remove self loop

    - by StereoMatching
    Try to write a Karger’s algorithm with boost::graph example (first column is vertice, other are adjacent vertices): 1 2 3 2 1 3 4 3 1 2 4 4 2 3 assume I merge 2 to 1, I get the result 1 2 3 2 1 1 3 4 2 1 3 4 3 1 2 4 4 2 3 first question : How could I change the adjacent vertices("2" to "1") of vertice 1? my naive solution template<typename Vertex, typename Graph> void change_adjacent_vertices_value(Vertex input, Vertex value, Graph &g) { for (auto it = boost::adjacent_vertices(input, g); it.first != it.second; ++it.first){ if(*it.first == value){ *(it.first) = input; //error C2106: '=' : left operand must be l-value } } } Apparently, I can't set the value of the adjacent vertices to "1" by this way The result I want after "change_adjacent_vertices_value" 1 1 3 1 1 1 3 4 2 1 3 4 3 1 2 4 4 2 3 second question : How could I pop out the adjacent vertices? Assume I want to pop out the consecutive 1 from the vertice 1 The result I expected 1 1 3 1 3 4 2 1 3 4 3 1 2 4 4 2 3 any function like "pop_adjacent_vertex" could use?

    Read the article

  • how to declare object variable name in loop

    - by user3717895
    public class Node{ Node p,l,r; int height; String s; { /** class body**/ } } String[] S=new String[5000]; int i=0; while (i<5000){ Node x=new Node(); x=S[i]; } I want to make 5000 Node object. above code assign same variable name x every time but i want different variable name . then how to declare 5000 class variable name without declaring it manually. is there something by which i can create 5000 Node class object with ease.

    Read the article

< Previous Page | 60 61 62 63 64 65 66 67 68 69 70 71  | Next Page >