w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Javascript: Iterating over an array causes an infinite loop?
A loop only can be infinite if the condition is always true. In your case it looks that it should reach a false , but provably formData is getting new elements each iteration of the loop or i is being modified and returned to previous values. What I recomend is to create variables that will be used only for comparasion purposes: var max = fromdata.length; for (var count = 0; count < max; count++) { var i = count; // your stuff using formdata and i Now max and count will not be modified by the code in the loop and the loop will reach an end.

Categories : Javascript

Using Jackson 2.2 to serialize Hibernate result into JSON string, infinite loop
AYE! After 2 days I finally found my mistake. I forgot to register the Hibernate3Module. My criteria/mapper code is now: Criteria criteria = session.createCriteria(EvalMasterEvalDetail.class) .add(Restrictions.eq("active", "Y")) .setFetchMode("evalMasterEvaluation", FetchMode.JOIN) .createAlias("evalMasterEvaluation", "eval") .add(Restrictions.eq("eval.id", evalId)) .addOrder(Order.asc("detailOrder")); details = criteria.list(); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new Hibernate3Module()); json = mapper.writeValueAsString(details); evalMasterEvaluation values are missing, but it's a step in the right direction.

Categories : Json

Javascript continue statement in while loop causes an infinite loop
continue makes you go back to the beginning of the loop. You probably wanted to use break instead. Or maybe make your decrement before the if block.

Categories : Javascript

Loop enters infinite loop if cout is missing
Your program has undefined behavior, because you are trying to use the value of an uninitialized variable here: while (stringPos < 1) // ^^^^^^^^^ // This is uninitialized And here: found1 = inString.find(frame1, found1); // ^^^^^^ // This is uninitialized Besides, even supposing your variables were initialized, you have a semicolon that makes your while loop either a no-op or an infinite loop (as hmjd correctly points out in his answer).

Categories : C++

QThread event loop and infinite work loop
A call to QCoreApplication::processEvents should work, but maybe a better solution is to use a QThreadPool instead of forcing a thread to keep running.

Categories : Multithreading

Android Iterating JSON Array containing JSON Object
You are using the same Cast object for every entry. On each iteration you just changed the same object instead creating a new one. This code should fix it: JSONArray jCastArr = jObj.getJSONArray("abridged_cast"); ArrayList<Cast> castList= new ArrayList<Cast>(); for (int i=0; i < jCastArr.length(); i++) { Cast person = new Cast(); // create a new object here JSONObject jpersonObj = jCastArr.getJSONObject(i); person.castId = (String) jpersonObj.getString("id"); person.castFullName = (String) jpersonObj.getString("name"); castList.add(person); } details.castList = castList;

Categories : Java

Loop not iterating
You set RABBITS and RABBIT_BIRTH_RATE at the beginning. Then, on every loop iteration, you set RABBITS_START to some formula involving these two numbers. You never change the value of RABBITS or RABBIT_BIRTH_RATE or FOXES or anything, so every time you run through the loop, you're just calculating the same thing again with the same numbers. You need to update the values of your variables on each iteration --- that is, set a new value for RABBITS, FOXES, etc.

Categories : Python

SQL While loop getting stuck in infinite loop
I do not undestand your script, but maybe this will be useful: declare @colname as varchar ='' while NULLIF(@colname,'') is not null begin Select @colname = col1 FROM Table1 WHERE col1 in ('test1','test2','test3') end Your problem is on the "While condition", because '' <> NULL. Maybe you can this too: while isnull(@colname,'') <> '' or while coalesce(@colname,'') <> '' Anyway I suppose that your query is a little more complex for use this WHILE it this way.

Categories : SQL

Iterating an empty matrix using a for loop
The for loop runs over all columns of its input. Since a 0x1 matrix has one (empty) column, the loop will simply go over that. No exception is mentioned for empty matrices, so here t will simply be the empty matrix as seen from: for t = ones(0, 1) %// Iterate over an empty 0x1 matrix size(t) % t is a 0x1 matrix end Is it a bug? Probably not. Does it make sense? Well, I think I would prefer the loop not to execute if the input is empty, but probably there are advantages to this as well. At least it is definitely something to be alert of!

Categories : Matlab

Return value from function when iterating in a loop R
The problem is that you do not get the result of your function: inPvec<-c() #predefine vector to concatenate results into for (x in tabs){ #tabs holds multiple tables as a list inPvec<-c(inPvec,myFunction(x)) #concatenate results from each iteration } and you should correct your function too: myFunction<-function(tab){ #takes tabular input inP <- c() for (x in 1:dim(tab)[1]){ #iterate over rows rname<-rownames(tab)[x] #rownames as output if(rname=="something") inP<-c(inP,rname) #trivial work } return(inP) #return the vector made above }

Categories : R

How to get out of my infinite loop in c#
Take a look at this site for the background worker. It's really easy to implement and should be able to take care of your issue. http://www.dotnetperls.com/backgroundworker

Categories : C#

Why does this cause an infinite loop
counter = counter++; The above code has no effect on counter. It is effectively same as: int temp = counter; counter++; counter = temp; So, the value of counter is not changing at all. On the other hand, if you use: counter = ++counter; The counter is incremented first, and then is re-assigned to counter. Essentially, you can simply ignore the assignment part, and keep it simply this: counter++; // Or ++counter

Categories : Java

Infinite for loop
Your second example is not an infinite loop, just wait 1 minute. long endTime = startTime + 60000; set the endTime to 60000 milliseconds in the future, that means 60 seconds, means 1 minute. The standard output is just printing extremely fast. Put a Thread.sleep(1000L) in the loop and you will see 61 statements being printed before it ends. long endTime = 1378140843604L; // for example for (long now = 0; now < endTime; i++) { now = System.currentTimeMillis(); // will be 1378140783604, 1378140784604, 1378140785604 and so on System.out.println("now" + now); System.out.println("end" + endTime); Thread.sleep(1000L); }

Categories : Java

Why is this for loop infinite?
It looks to me like @Bart is on the right track here. You have nested loops that are modifying the same variables. This is generally a sign that something is wrong. Try renaming your inner-loop r and c variables.

Categories : C++

Why an Infinite Loop
If cin does not receive valid input for the data type (int), the variable grade is not changed and remains at -1. You can test whether the input was successful like so bool success = (cin >> grade); if (! success) { cin.clear(); cout << "bad input "; break; } You can also use this as a shortcut if (! (cin >> grade)) Note that you need to clear the error state of cin before you use it again.

Categories : C++

Why is my loop not going infinite
n will underflow somewhen because int is signed and has a value range of -2147483648 to 2147483647 for example (x86). Somewhen n will get more positive than i. Edit: The loop has at most 1 iteration. Edit 2: The loop would have no iterations if n would have the value -2147483648 for example because -2147483648 - 1 will make the value positive (two complement integer arithmetic). But this could never the case because the pre condition is that n may not be negative.

Categories : C

iOS: iterating this json file
In ViewController.h NSString *idStr; NSString * usernameStr; NSMutableArray *dataSourceArray; NSMutableDictionary *MutableDictionry; In ViewController.m -(void) viewDidLoad { dataSourceArray =[NSMutableArray new]; NSArray *array;//this array will contain your json dataSourceArray = [self usersFromArray:array]; } - (NSMutableArray *)usersFromArray:(NSArray *)array { NSMutableArray *users = [NSMutableArray array]; for (NSDictionary *dict in array) { if (dict) { idStr = dict[@"id"]; usernameStr = dict[@"username"]; MutableDictionry=[NSDictionary dictionaryWithObjectsAndKeys:idStr,@"id",usernameStr,@"username",nil]; } [users addObject:MutableDictionry]; } return users; }

Categories : Iphone

Iterating through JSON object
Try using this: $.each(obj.query.results.viewentries.viewentry, function (index, value){ $.each(value.entrydata, function (index, value) { if (value.name == "kopregel") console.log(value.text); }); }); Here it is working: http://jsfiddle.net/8tKYd/2/

Categories : Javascript

Iterating in a JSON in javascript
If you have a json as a string you can use var json = JSON.parse(jsonString); this will return an object array on which you can iterate. See more here

Categories : Javascript

Json Iterating using java
name_value_list is also an Object. JSONObject job2 = new JSONObject(job.get("name_value_list")); So there you get job2.get("user_default_dateformat"); Every {} in your JSON is an object. So for every String you get which is something like {"xy":"za","ab":"cd"} you have to cast it to the JSONObject Edit for your error: As you can see in your code the line: JSONObject job2=new JSONObject(job); will try to generate a JSONObject out of your JSONObject. You have to get the JSONObject in your JSONObject. You want to get the user_default_dateformat which is in your JSONObject: String name_value_list_string = job.get("name_value_list").toString(); //this string is another json-string which contains the user_default_dateformat JSONObject name_value_list_object = new JSONObject(name_v

Categories : Java

Excel VBA Iterating Through Files - Stuck in a Loop
Sub runMe() Dim FSO As New Scripting.FileSystemObject Dim File As Scripting.File Dim path As String With Application .ScreenUpdating = False .DisplayAlerts = False .EnableEvents = False End With path = ActiveWorkbook.Path & " emplates" For Each File In FSO.GetFolder(path).Files If InStr(File.Name, "~") = 0 _ And LCase(FSO.GetExtensionName(File.Name)) = "xlsm" _ Then With Workbooks.Open(File.Path, 3) Application.Run "'" & .Name & "'!doMacro" .Close SaveChanges:=True En With End If Next With Application .ScreenUpdating = True .DisplayAlerts = True .EnableEvents = True End With End Sub Your For Each

Categories : Excel

Node.js - Async Whilst loop not iterating
SOmething like this? I didn't test it because I don't know what DB module you're using, but the logic should be obvious. function searchNubmersForResults(firstNumber, callback) { //place other variables here, and you can collect the results within the closure, and send them as arguments to your callback function testNumber(uniqueNumber) { var uniqueNum_string = uniqueNumber.toString(); newUnique = data.id + uniqueNum_string; db.collection('landmarks').findOne({'id':newUnique}, function(err, data){ if (data){ console.log('entry found!'); callback(data);//We're done, use the callback on the data } else { console.log('entry not found!'); testNumber(uniqueNumber++);//Lau

Categories : Javascript

SendKeys getting into infinite loop
Apparently your button1 has the focus after being clicked. Now sending Enter presses the button another time. To solve that you need to set the focus before sending keys to wherever your keys should go to (another app, another control).

Categories : Wpf

Why this below program is going for infinite loop?
you need to do foo(--n) and not foo(n--) --n will decrement the value of n, and then send the decremented value n-- will decrement the value of n, but send the pre-decremented value. so when you do foo(n--) you decement the value of n, but send to the foo function the n bofore decrementing. as you can guess that will go forever void fun(int n) { if(!n) { cout << n << " " << endl; } else { cout << n << " "<<endl; fun(--n); } } int main() { int n = 5; fun(n); system("pause"); return 0; } to learn more on the difference between n-- and --n read here

Categories : C++

Why is this code an infinite loop?
This is incorrect $var.$i = "any"; because this expression is equivalent to: $var.($i = "any"); Which assigns $i to new value, therefore the condition of which the while loops checks will always be true.

Categories : PHP

Execution of infinite loop in c exe vs c# exe
Your C# program is in a form. Windows expects the form to be able to process events (e.g. telling it to close) but it can't because it's in the infinite loop. If the infinite loop was in its own thread, or you wrote a C# console application instead of a form-based one, I think it would behave more like your C.

Categories : Windows

Why does this go into an infinite loop? (Pig Latin)
In both loops, if the if condition is false, then the while loop variable is never incremented. Voilà! Infinite loop. I haven't reversed engineered your logic, but you probably want to increment the loop variables (b and x) each time through the loop, not just when the if condition is satisfied.

Categories : Java

Why I got an infinite loop in my ifstream?
Because in your operator >> (istream& is, Point& p) you're using cin instead of is. You'll always get an infinite loop, as is is ok before you run the loop and the loop doesn't alter is.

Categories : C++

Infinite loop code in C
why are you using a loop, your logic seems that it must have a if ---else condition while (1) { if (a>=1&&a<=100) { printf("wrong value entered. enter again "); scanf("%d",&a); } else { printf("you enter %d. Thanxz",a); return 0; } }

Categories : C

Infinite loop in Tkinter?
Try writing your function this way instead. You should be scheduling your code to run, not looping it. def update(money=0, increase=100, repeat=30): money += increase label.set(money) label._master.after(repeat * 1000, update, money, increase, repeat)

Categories : Python

Infinite Loop Banner
I think you just have some syntax issues. Arrays in PHP are in this form: $images = array('1.jpg', '2.jpg', '3.jpg'); if you want a random image use: $image = array_rand($images); Cheers!

Categories : PHP

Infinite feof loop
PHP is actually sending the data right away; the problem is Perl isn't doing anything with it. If you do this: my $data = <$connection>; print $data; #add this line if($data != "1234") { .... and then kill the PHP script with Ctrl-C (Windows -- don't know what the command is if you're using Linux), the Perl script will immediately output "1234". It's hanging up on the angle bracket operator because that is a readline (i.e. it's looking for a newline and never finding one). Either of the following got your code to work for me: //in the PHP file fwrite($socket, "1234 "); or #in the Perl file (instead of my $data = <$connection>) my $data; $connection->recv($data, 1024); Edit: see comments below before just implementing a change. As hobbs mentions, recv is probably no

Categories : PHP

unsigned int causes infinite for-loop
An unsigned int can never be less than 0. That's what makes it unsigned. If you turn on some warning flags, your compiler should tell you about your problem: i >= 0 is always true for an unsigned value. Clang, for example, required no special flags at all to warn: example.cpp:5:29: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare] for (unsigned int i=3; i>=0; --i) ~^ ~ 1 warning generated. GCC required -Wextra: example.cpp: In function ‘int main()’: example.cpp:5: warning: comparison of unsigned expression >= 0 is always true

Categories : C++

angular js '?' in ng-src causes infinite loop
Well I think the problem is the getRandom function returning a different value every time it's called. Here's what happens: Angular call your function Gets the value See's it's different from the previous value Marks the cycle as dirty After the cycle is finished it re-runs the cycle thus getting a new value ... The idea would be to have getRandom give discreet values over a period of time. For example only give a new value every 1, 10, 30 sec whatever you see fit. This advice applies to many things, actually. Angular provides no guarantees about how many times it will call your functions that are found in bindings. So you need to make them fast and also you need to make sure that for the same input they return the same output(most times, though in this case it might be justified). A

Categories : Angularjs

infinite loop in python?
if (K==0) should probably be if (k==0) Just a typo... It is easy to localize this problem - you know where you want to terminate your loop and the only thing which can go wrong is your if statement. Spotting such things is easy and one of the most basic things to master in programming. You need to learn debugging as soon as your programs start to be longer than 5 lines.

Categories : Python

Notification Infinite Loop
Hmm well you should check your flags again! FLAG_ONLY_ALERT_ONCE Bit to be bitwise-ored into the flags field that should be set if you want the sound and/or vibration play each time the notification is sent, even if it has not been canceled before that. So my guess is that with this flag you will get your notification to vibrate all the time. From the official docs http://developer.android.com/reference/android/app/Notification.html

Categories : Android

as3 how to stop an infinite loop?
All you need to do is kill the event listener if you're already on your target page, consider the following: import flash.external.ExternalInterface; addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler); function fl_EnterFrameHandler(event:Event):void { var gotoURL:String = "http://www.levittproperties.com/sitebuildercontent/sitebuilderfiles/homepage.swf"; var currentURL:String = ExternalInterface.call("window.location.href.toString"); if(gotoURL != currentURL) { navigateToURL(new URLRequest(gotoURL), "_self"); } else { Event.currentTarget.removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler); } }

Categories : Actionscript

eof in perl- going in infinite loop
An eof without an argument uses the last file read. Using eof() with empty parentheses is very different. It refers to the pseudo file formed from the files listed on the command line and accessed via the <> operator. EDIT: Normally you dont need to use eof, because the input operators typically return undef when they run out of data, or if there was an error. CODE: Maybe the Problem is, that you dont use the 2nd condition of the for loop. tie my @lines, 'Tie::File' , "abc.txt" or die; for(my $i=0;$i<=$#lines; $i++) { if ($lines[$i] =~ /^[s]*hello/){ splice @lines, $i, 1, "#$lines[$i]", "hi"; last; } }

Categories : Perl

rpart - infinite loop
The problem may be related to the fact that some of the classes have very few observations (and some have 0, but these are ignored). Since you say tree works fine I assume the slowness is somewhere in the pruning phase of the rpart algorithm. This is the phase where the tree has already been build but the rpart algorithm decides to reduce overfitting by removing some of the partitions (branches). A quick fix may be to predict whether a subject suffers from any form of Arrhythmia (i.e, class 1 vs the rest).

Categories : R

Infinite loop - what is happening?
You only declare 4 elements for re (0 through 3 inclusive) but you use a 5th element when doing re[4]. You are invoking undefined behavior at that point. You need to define re as: char re[5];

Categories : C



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.