w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
finding loop invariant for two nested while loops java
You should work out the invariants of nested loops starting with the inner one: while (j != 0) { if (A[j] > A[k]) { k = j; } j--; } you can observe that A[k] >= A[x], for any (j < x) && (x <= i) At the end of the loop, j == 0, so using Hoare Tripple for the while loop you can state that at the end of the inner loop A[k] >= A[x], for any (0 < x <= i) This is another way of saying that A[k] is MAX(A[0:i]). Now you can proceed with the outer loop: since i proceeds from A.length down to zero, the invariant would be A[y] < A[x], for any (y >= i) for any (y < x <= Length(A)) Using Hoare Trippe once again, you derive that upon exiting the outer loop the array A is sorted in ascending order: A[y] < A[x], for any (y >=

Categories : Java

Very high processing difference between two almost similar while loops
I would guess that it's one or both of the following. Chrome is resizing the underlying hashtable somewhere between 338 * 338 and 339 * 339. Garbage collection is happening in the same timeframe. I doubt this is a memory issue.

Categories : Javascript

Django nested for loops: Is it possible to use the result from the first loop within the definition of the second for loop?
I would say that the collection should look more like sectList = {"Id": 1, "Section": "Home", "Identifier": {"Id": 1, "Title": "Home", "Url": "home/","Id": 2, "Title": "My Account", "Url": "account/","Id": 3, "Title": "Full List", "Url": "fullList/",}} You see - "Identifier": "homeList" is not really a link to your second list. Its just a prop. name and value.

Categories : Python

Is there a command in java to make the program go back to the beginning of a loop
You can use the continue statement to continue to the next iteration. That said, I don't see a loop in your sample code. You can loop with a for, while or do/while. The do/while loop executes at least once -- which is typically what you want to do when asking the user a question. This Java tutorial for Branching Statements provides this example of a continue statement in a for loop. for (int i = 0; i < max; i++) { // interested only in p's if (searchMe.charAt(i) != 'p') continue; // process p's numPs++; }

Categories : Java

java Android - how can I make WebView transparent for android 2.x?
This worked for me : myWebView.setBackgroundColor(Color.TRANSPARENT); OR add as part of html here is my code snip : String css = "<head><style >* {word-wrap: break-word;margin:0;padding:0;font-size:15px; text-align:justify;font-family: Arial, Helvetica, sans-serif}</style></head>"; myWebView.loadData(css, "text/html", null); myWebView.setBackgroundColor(Color.TRANSPARENT);

Categories : Android

Powrshell Loop within Loops
I think the problem (or one of the problems) is this line: foreach ($folders in $folders). It should be foreach ($folder in $folders) and then everywhere in the for loop that you refer to the current folder you should use $folder (not $folders). Give that a try and see how it looks.

Categories : HTML

While loop not running because of if loops
Because it blocked at the os.system(cmd1) What's your purpose to ssh the server? Maybe you can have a view on the paramiko: a ssh python lib. If your cmd may block, you can also have a view on python threading and Queue Just like : import threading class ssh_client(threading.Thread): def __init__(self, ssh_host): super(ssh_client, self).__init__() self.ssh_host = ssh_host def run(self): """Do something """ pass ... if __name__ == "__main__": while True: print('Enter name of server...') print('......................................................................') server = input ('') if server == '1': ssh_client_1 = ssh_client("192.168..1.12") ssh_client_1.start()

Categories : Python

How long would it take for a For loop to run through 1000 loops?
To end a loop early use the break; statement. But, as you're obviously trying to check whether or not a name already exists in a SQL table you probably should rather directly ask the database for the information: select true from YourUserTable where name = 'theName' limit 1 Then check whether 1 or 0 rows are returned. If one row is returned the name already exists; if the result set is empty the name is still available. This is much faster than first getting the whole user name list from the database and then manually check it. If you still want to iterate: $found = false; // Of course, a for loop is also possible foreach ($namesArray as $position => $name) { if ($name == $nameYouAreLookingFor) { $found = true; break; } } if ($found) echo "The name alre

Categories : PHP

Loop unrolling with dependent loops
Perhaps not the most elegant solution, but you could use macros: #define INNER_L_LOOP(l) { diml = a[l-1]; dimkl = dimk*diml; dimijkl = dimij * dimkl; } #define INNER_K_LOOP(k) { dimk = a[k-1]; for (l =k; l< nab+vab; l++) { INNER_L_LOOP(l) } } #define INNER_J_LOOP(j) { dimj = b[j]; dimij = dimi*dimj; count = count +1; for (k = nab+1; k< nab+vab; k += 2) { INNER_K_LOOP(k) if (k+1 < nab+vab) INNER_K_LOOP(k+1) } } #define INNER_I_LOOP(i) { dimi = a[i]; for (j = i; j< nab+vab; j+= 2) { INNER_J_LOOP(j) if (j+1 &

Categories : C

php for loop from array stops after 3 loops
Your problem lies here: for($i = 0; $i < count($nt); $i++) You are counting the elements of $nt (which are 3), but you want to access the elements of $nt[2] (which are 5). Thus, you need to change the above line to: for($i = 0; $i < count($nt[2]); $i++)

Categories : PHP

F# How do a create a loop in a console app that loops through a method until a certain key is hit
You need to actually define functions rather than just variables - you want something like member private this.SynchronousRespsonse() = let c = System.Console.ReadKey() if c.Key = System.ConsoleKey.Q then this.unsubscibe else let eventObj : Event = session.NextEvent() for msg in eventObj do printfn "%A" msg.ToString this.SynchronusResponse() Also, the extra rec binding is not required and you want the recursion to occur only in the else block so that you can return after Q is pressed

Categories : F#

Loop binding to find number of loops
Edit 1: True. My older answer doesn't function as I thought it might :). Having read the source, they don't seem to trigger any public events. Though they do seem to bind to some private one, ended.buzzloop. I couldn't find the said event being trigger in code, but maybe it might work for you As @koala suggested, implementing your own loop might turn out to be a better option. Old answer - doesn't work! I haven't used buzz.js before. Reading the docs, I found the playing & paused events. playing Sent when the media begins to play (either for the first time, after having been paused, or after ending and then restarting). My idea is to listen to these two events. If playing is raised without a pause having been raised, then you can increment your count.

Categories : Javascript

How can I determine which device a loop loops back to?
To be honest I do not understand what "light profiling" has to do with merging partitions or what you are really trying to accomplish but finding out which loop back device is associated with which file can be done with the losetup command. The code to do this needs to be running as root for this so you would run "sudo losetup -a". To do this same trick yourself in C/C++ the procedure would be Parse /proc/partions to find a loop device in use open each loop device fstat it to make sure it is a loop device ioctl LOOP_GET_STATUS ioctl LOOP_GET_STATUS64 All of the important information is in the header file linux/loop.h If any of the above sounds too strange and/or vague just use losetup.

Categories : C++

'while' loop in string compare function loops more than necessary
strcmp_kr(s1, s2) == 0 ? printf("Strings equal! ") : printf("Strings not equal by %d! ", strcmp_kr(s1, s2)); you have called strcmp_kr(s1, s2) twice ,first in the condition, and second in the printf since your condition is false, so you get 10 times of the print message. to avoid this, store the return value in a variable like int rtn = strcmp_kr(s1, s2); rtn == 0 ? printf("Strings equal! ") : printf("Strings not equal by %d! ", rtn);

Categories : C

Nested For Loops, inside loop not reacting
I don't fully understand what you are trying to achieve but the code you currently have will always produce values such as 01/01/20, 02/01/20, .... Your inner loop (For i = 13 To 20) loops always replacing i until it hits 20 (as x isn't being incremented). I suspect you want to re-arrange your loops to maybe something like this: For i = 13 To 20 For x = Cells(1, Columns.Count).End(xlUp).Column To 1 Step -1 If Cells(1, x).value = y Then Columns(x).EntireColumn.Insert Columns(x).EntireColumn.Insert Columns(x).EntireColumn.Insert Cells(1, x).value = "01/01/" & i Cells(1, x).NumberFormat = "mm-yy" Cells(1, x + 1).value = "02/01/" & i Cells(1, x + 1).NumberFormat = "mm-yy" Cell

Categories : Excel

C++11 range-based for loops without loop variable
There may be a way to do it but I very much doubt it would be more elegant. What you have in that first loop is already the correct way to do it, limiting the scope/lifetime of the loop variable. I would simply ignore the unused variable warning (it's only an indication from the compiler that something may be wrong, after all) or use the compiler facilities (if available) to simply turn off the warning at that point.

Categories : C++

jQuery - how to loop through rows on two similar tables
You need to go through 2 steps: - Define number of tables: var $tables = $("body").children("table.tabResult"); - Variable $tables is an array of your similar tables. Therefore, you can loop through each table and get all the rows using "for" statement. This approach will work with different number of cells in each table

Categories : Jquery

nested loops, how to make a calendar
Seems like this is a homework problem, so I'm not going to give you the code, but you're heading in the right direction. First, I'd change System.out.print("x"); to System.out.print(" x"); //Add two spaces in front of the x so you have space between the numbers. Next, to generate actual numbers instead of x's, put int dayOfMonth = 1; above the for loop. You'll then want to print out dayOfMonth instead of x's. The problem I leave to you is how to make the value of dayOfMonth increase each time.

Categories : Java

With nested loops, in what order do the loop variables get incremented?
The code works from top to bottom in the order it appears. If it helps to see it a little better (I wouldn't recommend you code like this, but just shows the logic a bit better): for i := 1 to 5 do begin for j := 1 to 5 do begin x[i, j] := i + j; end; end; The logic starts from i = 1 and then counts the inner loop. So basically, you're doing this: x[1, 1] := 1 + 1; x[1, 2] := 1 + 2; ... x[1, 5] := 1 + 5; x[2, 1] := 2 + 1; .. x[5, 4] := 5 + 4; x[5, 5] := 5 + 5; Hopefully this helps you understand how for loops work in this case.

Categories : Delphi

Multiple Wordpress Loops - second loop is repeating the same post
thesecondI got it working changing the loop to this: // Loop 1 $first_query = new WP_Query( $args1 ); while($first_query->have_posts()) : $first_query->the_post(); get_template_part( 'content-1', get_post_format() ); endwhile; wp_reset_postdata(); // Loop 2 $second_query = new WP_Query( $args2 ); while($second_query->have_posts()) : $second_query->the_post(); get_template_part( 'content-2', get_post_format() ); endwhile; wp_reset_postdata();

Categories : Wordpress

Trying to use a Nested For Loops w/ 2 variables, Keeping 1 the same while running through the first for loop
I'm assuming this part is the real problem: So Im trying to figure out how to use 2 for loops only (I have not learned dictionaries and above) to have the first for loop for the Towers themselves, then a second for loop for all the towers except the ones chosen in the first loop. So you want to loop over all of the towers except i, right? The easy way to do that is to loop over all of the towers, and just skip i. For example: for i in towers: for j in towers: if j == i: continue # do stuff with i and j Or, equivalently: for i in towers: for j in towers: if j != i: # do stuff with i and j

Categories : Python

Python: Return string using while loop (no methods or for loops)
Why don't you use str.replace(), available in Python? >>> s = 'razzmatazz' >>> s.replace('z', 'r') 'rarrmatarr' No need to create a custom function to get done what you want

Categories : Python

How to make a "progressbar" similar to Gmail or G+?
There is no built-in component in Android that does what you want. I suggest you use the third party ActionBar-PullToRefresh instead.

Categories : Android

jQuery getJson in a loop stops looping after n number of loops
I looked at the error log of my live server and found this: [Thu Aug 29 23:44:00 2013] [error] [client xxx.xxx.xxx.xxx] (12)Cannot allocate memory: couldn't create child process: /somedirectory/suphp/sbin/suphp for /some/home/public_html/xxx.php, referer: http://example.com/ I added a 1 second delay before every request and also changed memory_limit = 16M; to memory_limit = 256M; in php.ini. (shared hosting) No problems so far. (Thanks @RobSchmuecker for pointing me in the right direction)

Categories : Javascript

Make column as header and combine similar id in one row in sql
SELECT ItemCode, MAX(CASE `month` WHEN 'Jan' THEN qty END) AS Jan, MAX(CASE `month` WHEN 'Feb' THEN qty END) AS Feb, MAX(CASE `month` WHEN 'Mar' THEN qty END) AS Mar, MAX(CASE `month` WHEN 'Apr' THEN qty END) AS Apr FROM Table1 GROUP BY ItemCode See it working live in an sqlfiddle. MySQL does not have a handy PIVOT function like i.e. SQL Server, so you will have to live with code like above. But in my opinion, output formatting should be done on application layer anyways, not in DB layer.

Categories : Mysql

Inheritance from object Application, how do I make something similar to that?
Make it a class instead of object: class MyApp[C123, C456] extends App { val system = ... val myActor = ... val b = ... } package com.project1 object Application1 extends MyApp[com.project1.Class123, com.project1.Class456] { ... } package com.project2 object Application2 extends MyApp[com.project2.Class123, com.project2.Class456] { ... }

Categories : Scala

How to make Selenium test pass when two images are very similar?
Sikuli would be the way to go when you are required to compare images. Have a look @ the video named "Webdriver & Sikuli integration" in this page http://www.sikuli.org/testing.html

Categories : Ruby

How to make TextEdit/TextView style similar to Viber
Use this website to generate whatever you want http://android-holo-colors.com/. Because you will put these drawables into your app so it doesn't matter which version you are targeting. Your app will look similar. Cheers.

Categories : Android

How to make number not reachable (similar to call blocker)?
The "Not Reachable" signal is not sent by your phone. Instead, it is sent by your carrier. When your number is not reachable, it literally means the cell tower can't reach you. So when someone calls you, the tower tries to find you, and if it can't it send the "Not Reachable" signal down the line. You can't fake one and send it from your device instead.

Categories : Java

How to make android studio (gradle) use Sun/Oracle Java?
org.gradle.java.home Specifies the java home for the Gradle build process. The value can be set to either jdk or jre location, however, depending on what does your build do, jdk is safer. Reasonable default is used if the setting is unspecified. http://www.gradle.org/docs/current/userguide/build_environment.html

Categories : Gradle

continue takes you to top of your while loop in python. Is there something similar that will take interpreter to beginning of your code
You could wrap what ever piece of functionality you have in a function or method, then simply call the function/method whenever you need it. def print_ten(): n = 1 while n <= 10: print n n = n + 1 print_ten() print_ten()

Categories : Python

How to write a single wordpress loop (not multiple loops) that prevents duplicate output
Create an empty array In your loop, add the brand to this array. If the brand already exist in the array, then don't add it and don't output the post. Pseudocode: $args = array( 'posts_per_page' => -1, 'category' => 1, 'order' => 'ASC', 'orderby' => 'title' ); $brand_list = array(); $posts_array = get_posts($args); foreach( $posts_array as $post ) : setup_postdata($post); $brand = get_post_meta( $post->ID, 'brand_value', true); if(!in_array($brand,$brand_list){ array_push($brand_list,$brand); echo 'brand: '.$brand; the_content(); } endforeach;

Categories : Wordpress

Make a Flip animation (or something similar) when I reload the content of my UIWebView
You can always do the +transitionWithView:duration:options:animations:completion: method with the web view. [UIView transitionWithView:self.webView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionAllowAnimatedContent animations: ^{ [self.webView loadHTMLString:@"<strong>Hello world</strong>" baseURL:nil]; } completion:^(BOOL finished) { }]; This method is basically a way of saying: "change the contents of this view, in animated fashion". So it takes an snapshot of the current state, performs the animation (be it a flip, curl, etc) and then inserts an snapshot of the new state. But notice that I've used UIViewAnimationOptionAllowAnimatedContent, this forces the animation to not use a snapshot for the new state of the view, because

Categories : Iphone

Android java - how to make Activity wait until Service is binded?
I think you want that: http://developer.android.com/guide/components/bound-services.html. On this page you can find: /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get LocalService instance LocalBinder binder = (LocalBinder) service; mService = binder.getService(); mBound = true; } @Override public void onServiceDisconnected(ComponentName arg0) { mBound = false; } }; The onServiceConnected method is called when the service is ready and you can do your stuff inside (or use the mBound att

Categories : Java

Start an android service inside the same service to make a loop
You could create a thread in your service and put while loop there like this: new Thread(new Runnable(){ public void run() { // TODO Auto-generated method stub while(true) { Thread.sleep(60000) //REST OF CODE HERE// } } }).start(); But this is an easy quick fix, overall, creating a thread that sleeps all the time is not a good solution for mobile devices. You should consider using AlarmManager instead. It handles recurring events very well and was specifically designed for similar scenarios.

Categories : Android

Ways to make a change listener for all HTML objects following similar ID structure?
You could delegate it to the parent: var table = document.getElementById('parentTable'); table.addEventListener('change', function(ev) { var target = ev.target; // where the regex below matches the pattern if ( target.id.match(/(.*?)-(d+)-(d+)/) ) { console.log(target); } }); Please note that the change event does not bubble in IE < 9. You may be able to use onpropertychange for those, but I don't know for certain. Using jQuery would also allow the change event to bubble in previous versions of IE.

Categories : Javascript

How to make Alert, Prompt and confirm dialog of javascript in java Android
Example javascript code: var a = prompt(""); Android does not support that sort of blocking UI call. Instead, use listeners to notify something within your app when the user has accepted the dialog (e.g., pressed the OK button).

Categories : Java

Javascript, setInterval starts after while loop? how to make it start inside while loop?
What is happening is you are asking the computer to run the nested inner function once per millisecond. And you are asking this to be done ten times in a row, so by the end, the computer should be sending an alert exactly ten thousand times per second. I'm surprised it doesn't consume all the CPU and consume all memory and cause a fatal error. This will continue until you call clearInterval(), or until the window is closed. http://www.w3schools.com/jsref/met_win_setinterval.asp

Categories : Javascript

Make an If statement from stuff inside a foreach loop outside the loop?
As you might already experienced the construct you propose is not desired since the if statement will be executed after the loop has already ended. You can use the continue keyword to jump to the next iteration and skip fields you're not interested in. foreach ($section['fields'] as $k => $type) { if ($type['type'] != 'switch') { continue; } // do stuff } http://php.net/manual/en/control-structures.continue.php

Categories : PHP

Is there anything similar in C#/Java to do the following?
One option is to use a projection with LINQ: myCollection.Select(element => new MyOtherType { ... });

Categories : C#



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