w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
loop json array and return values in php
use json_decode //array $data = json_decode($json, true); foreach($data["data"]["formaspago"] as $row) { echo $row["Formapago"]; } Thanks @JimL for the hint.

Categories : PHP

Is it possible to use Yield keyword to return values without a loop?
Yes, absolutely: public IEnumerable<int> GetValues() { yield return 10; yield return 5; yield return 15; yield return 23; yield return 1; } You can have other code between the yield return statements, too. Although there are some restrictions about the code within iterator blocks, you can mostly use the normal code constructs - loops, conditions etc. On the other hand, if you don't need any other code, why not just return a list or array (or something similar)? public IEnumerable<int> GetValues() { return new int[] { 10, 5, 15, 23, 1 }; } If you have more specific requirements, please give us more details.

Categories : C#

Can you return a string from a while loop without using the return command?
The return statement returns a value from the entire method you're in. But you're in main, which can't return a value (it's void). If you want to end the while loop when you have a good value, then use the break statement to break out of the while loop. Control then passes to the next statement following the end of the loop.

Categories : Java

R Optimise a while loop nested in a for loop to introduce missing values in a dataframe
I am not sure if this is what you are looking for: library(missForest) data1<-iris[1:70,1:4] for(i in 1:28){ data1[i,]<-prodNA(mydata[i,],noNA =0.10) } table(is.na(data1)) n<-10 data2<-do.call("rbind", replicate(n, data1, simplify=FALSE)) table(is.na(data2)) data3<-prodNA(data2,noNA=0.55) > table(is.na(data3)) FALSE TRUE 1133 1667

Categories : R

Methods that return meaningful return values
You could create and return an enum with expected LoginResults. public enum LoginResult { Success, AccountSuspended, WrongUsername, WrongPassword, } Then return using the enum type in your method: public LoginResult LoginToTwitter(String username, String password) { // Some code to log the user in }

Categories : C#

Vlookup macro doesn't return all values needed but the values are input to pull from
A B C D E F 1 Adam 1 Adam 2 Peter 3 John 3 John 4 Phil 4 Phil 6 #N/A A B C D E F 1 Adam 1 Adam 6 Peter 2 Peter 3 John 3 John 4 Phil 4 Phil 6 Peter Cell D1 Contains the formula: =IF(ISERROR(INDEX(B:B,MATCH(C1,A:A,0))),INDEX(F:F,MATCH(C1,E:E,0)),INDEX(B:B,MATCH(C1,A:A,0))) Copy it down.

Categories : Excel

Use a loop to assign values to variables in different objects with an auto "fill the rest with default values"
I think I understand what you're asking. You currently have: Ask for value, put into Object1 if not done Ask for value, put into Object2 else put default into Object2 if not done Ask for value, put into Object3 else put default into Object3 ... You want: for x if not done Ask for value, put into Objectx else put default into Objectx Unfortunately that's not really possible. There is a way to do something similar, but you won't have real "named variables". Using a Map<String, SomeType> (or whatever it is in java) you can do Map<String, SomeType> dict = new ... for(int x = 0; x < 10; x++) if not done Ask for value, put into dict["object"+x.ToString()] else put default into dict["object"+x.ToString()]

Categories : Java

Excel - how to look up a table for two values and return another value if these two values match
I would think a PivotTable may solve your problem. Step 1: Create a PivotTable. Step 2: Use Index - Match and Array formula to get the matching of the two 'criteria'. Link: https://docs.google.com/spreadsheet/ccc?key=0AqU9Z4LZATBedHdDVFpVcmVzU2JQWGtyajltakk5WWc&usp=sharing

Categories : Excel

for loop returning unexpected values when squaring values
You iterate over the list by using for elem in testList, which yields elements of the list and not their indices. >>> b = [1, 3, -4, 5, 5, 3, 2, 1, 4, 8, 9] >>> for i in b: print i, 1 3 -4 5 5 3 2 1 4 8 9 # Whereas you expected 0 1 2 3 4 5 6 7 8 9 10 So, your code fetches the elements using the values as the indices and returns the square of those values. This is what happens - >>> for index, val in enumerate(b): # enumerate yields an (index, value) tuple which gets unpacked. print '{0} : {1}*{1} = {2}'.format(index, val, val**2) 0 : 1*1 = 1 1 : 3*3 = 9 2 : -4*-4 = 16 3 : 5*5 = 25 4 : 5*5 = 25 5 : 3*3 = 9 6 : 2*2 = 4 7 : 1*1 = 1 8 : 4*4 = 16 9 : 8*8 = 64 10 : 9*9 = 81 Whereas in your initial code, the a list happens to be the indices you

Categories : Python

Issue with Hashmap. Can not return All values when it has same key. How to get all values?
HashMap will override the value if a key for that value exists already. If you need to have more values for a key, you should use a Collection as value fro your HashMap: private HashMap<String, Vector<String>> mHashMap = new HashMap<String, Vector<String>>(); Vector<String> tmp = new Vector<String>(); tmp.add("ajay"); tmp.add("anand"); mHashMap.put("a", tmp); tmp = new Vector<String>(); tmp.add("hiren"); mHashMap.put("h", tmp); and so on..

Categories : Android

"None" as return from while loop
You need to initialize f to say, "". In the first itereation of while True f is None, so in the if condition it's testing None[:2] and None[2:] which will obviously raise error. EDIT: Well I wonder why don't you get object of type 'NoneType' has no len() error first....

Categories : Python

Using a VBA function, How can I fix my loop to copy cell values to a new row based on a matching cell values in a column?
Your code can be written in a better way but i just tried to correct your code. i hope it will help you. Sub finalDataMove() Dim LR As Long Dim varCol As Variant LR = Range("A" & Rows.Count).End(xlUp).Row For i = 1 To LR If Range("A" & i).Value = "11936" Then varCol = Application.Match(Range("B" & i).Value, [B:B], 0) Range("A" & i).Offset(0, 3).Copy Range("A" & varCol).Offset(0, 3).PasteSpecial xlPasteAll End If If Range("A" & i).Value = "12053" Then varCol = Application.Match(Range("B" & i).Value, [B:B], 0) Range("A" & i).Offset(0, 4).Copy Range("A" & varCol).Offset(0, 4).PasteSpecial xlPasteAll End If Next i Application.CutCopyMode = False End S

Categories : Excel

Return in a function while in loop
Use PDO::fetchAll(), it returns an array of all the results, rather than returning one row at a time: function Message($username){ $query = "SELECT * FROM msg WHERE `to` = '".$this->userid."' && `to_viewed` = '0' && `to_deleted` = '0' ORDER BY `created` DESC"; $stmt = $this->connection->prepare($query); $stmt->execute(); $this->messages = $stmt->fetchAll(PDO::FETCH_ASSOC); return $this->messages; } But to teach you about loops (a CS 101 concept -- what ever happened to people learning how to program?), here's how you would code it yourself: $stmt->execute(); $this->messages = array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)); $this->messages[] = $row; } return $this->messages;

Categories : PHP

Loop through XML to return all nodes
SELECT doc.value('./OrderItemId[1]/text()[1]','nvarchar(255)') AS 'OrderItemId', doc.value('./QuantityOrdered[1]/text()[1]', 'int') AS 'QuantityOrdered' FROM @xml.nodes('/ListOrderItemsResult/OrderItems/*') AS ref ( doc )

Categories : SQL

Sum the value of variable return by for loop in php
U can Try like this $powercost_total = '0'; for ($i = 1; $i<=9; $i++) { $manpowerCost = manpowerCost($project, $year.'-'.$m); $powercost_total = $manpowerCost + 4powercost_total; ....

Categories : PHP

How do I return the product of a while loop
By storing that product and returning that result: def calculate_product(n): product = 1 for x in range(n): product *= x + 1 return product Now we have a function that produces your calculation, and it returns the result: print calculate_product(5)

Categories : Python

When Does HashMap.values()/HashMap.keySet() Return By Reference And When Does It Return By Value?
To make a long story short, java objects have some very peculiar properties. In general, java has primitive types (int, bool, char, double, etc) that are passed directly by value. Then java has objects (everything that derives from java.lang.Object). Objects are actually always handled through a reference (a reference being a pointer that you can't touch). That means that in effect, objects are passed by value, as the references are normally not interesting. It does however mean that you cannot change which object is pointed to as the reference itself is passed by value. To simplify your problem see the below code @Test public void testIntegerValue() { Integer num = new Integer(1); setInteger(num); System.out.println(num); // still return one, why? because Integer will conve

Categories : Java

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

What causes Looper.Loop() to hang (i.e. never return)
Looper.loop creates an infinite loop and only stops when you call quit http://developer.android.com/reference/android/os/Looper.html#loop()

Categories : Android

Why does this always return false (nested for loop)
Because you are returning false always. return true is on other scope. You should write your code like this: var shouldDoThis = function(query) { // 1st level var should; documents.forEach(function(section) { // 2nd level section.words.forEach(function(word) { //3rd level if (word.content == query.content) { should = true; return; // you "quit" the 3rd level function. This returns to 2nd level } }); // end of 3rd level }); // end of 2nd level return should; }; // end of 1st level More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope

Categories : Javascript

Getting proper return from Wordpress Loop
This whole thing seems like a really bad idea. I would strongly recommend that you do things the right way: create a theme, and maybe put your whole site into WordPress. If that is out of the question, you should be able to get it to work by creating a custom query: <?php $new_loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1 // this will display all available posts ) ); ?> <?php if ( $new_loop->have_posts() ) : while ( $new_loop->have_posts() ) : $new_loop->the_post(); ?> // your loop code <?php endwhile; else: ?> // your code for when no posts exists <?php endif; ?> <?php wp_reset_query(); ?>

Categories : PHP

Is there any way I can return a value from a loop and continue from where I left off?
You can return from anywhere in your method , by just putting the return keyword. If you want to put a functionality to resume ur method from different places then u need to factor ur method in that way. You can use labels and if statements, set some static variables to mark the last execution place. If your application is not multi-threaded then u need not to worry with the use of static variable synchronization. Also if your method is too big and becoming hard to follow/read, then think about breaking it into smaller ones.

Categories : Java

C# return value invoke variables in loop
Your for loop is not guaranteed to iterate once, so you are getting a compiler error that temp may not have a value when you attempt to use it. Try: string temp = ""; Even better, though, would be to add proper testing to ensure that all of your inputs are as expected: if ( !System.IO.File.Exists( @"countryCode.txt" ) ) throw new ApplicationException( "countryCode.txt is missing" ); string[] data = File.ReadAllLines(@"countryCode.txt"); if ( data.Length == 0 ) throw new ApplicationException( "countryCode.txt contains no data" ); if ( data[0].Length == 0 ) throw new ApplicationException( "malformed data in countryCode.txt" ); string[] country = data[0].Split('#'); string temp = ""; for (int i = 0; i < country.Length; i++ ) { temp = country[i]; } return temp.Spl

Categories : C#

break does not seem to return to previous loop
It is because your break Exits the "While Loop" not the for loop...and im guessing your while loop only executes once? Why do you need while for that? Try this for (i = 0; i < time;i++ ) { DragonBoard.Write("w");//go forward if (int.Parse(bearingTxt.Text) - 1 > heading) { DragonBoard.Write("a");//turn left break; } else (int.Parse(bearingTxt.Text) +1 < heading) { DragonBoard.Write("d");//turn right break; } }

Categories : C#

Break a bash loop when [return] is hit
In case the user types <return> without typing anything else, $key will be an empty string. Just check for the empty string too: if [ -z "$key" ]; then break; fi As per the man page, -z tells checks for a zero length string.

Categories : Bash

passing values string values to an object and recieving a string in return in ios
Check your brain using NSLog in the (IBAction)kickit:(UIButton *)sender function. I guess you didn't initialise brain. If this is not the case, you need to provide more code.

Categories : IOS

How to return value from a for loop which is querying the database in Javascript?
I would probably make use of the complete callback, in jQuery terms. Have a counter that records how many records have been processed and update this in complete, as this executes on success or failure. Then when that counter is >= the length of the data array you can exit. As an aside, I would always do a >= rather than an == for the comparison you are doing there, that way, if for any crazy reason, the count is upped more than it should you still exit.

Categories : Javascript

how can i return an array created in a loop javascript?
Based on your description, it sound like tx.executeSql is asynchronous. That being the case, your Select method should return a Promise (also called a Future), or otherwise push the result back to the caller.

Categories : Javascript

jquery idiomatic early return from loop
I don't use coffeescript so this may not be perfect, but hopefully it gives you an idea: { someJQueryCallback: -> try $(someSelector).each -> throw new Error("STOP!") unless someCondition($(@)) moreStuff() catch error return false; }

Categories : Javascript

A variable returns nothing at foreach loop in php, but if i return before, it has value
I bet your $spts is empty, therefore no foreach loop is executed, therefore nothing is returned from a return inside the foreach loop. (PHP skips the loop, and the function comes to the natural EOF-Return.) try it with return count($spts) to see, if you have a result, and at least one iteration of the foreach. (but return that before entering the foreach, or you are facing the same problem again.) Also you could add a "no result" return after the foreach: foreach($spts as $spt){ return $var; } return "no result";

Categories : PHP

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

Loop within my single.php WordPress blog only return for one post
I think on single.php page you should use this for reference please check http://codex.wordpress.org/Function_Reference/get_post i am trying to solve your problem hope this help. thanks anand

Categories : PHP

How do I print the return value of a program in a loop in a batch file script?
What you need is delayed variable expansion: FOR /l %%x IN (1,1,10) DO ( AutomatedTest.exe cip.log ECHO !ERRORLEVEL! ) To enable delayed variable expansion precede your batch with SETLOCAL ENABLEDELAYEDEXPANSION or start command shell with CMD.EXE /V:ON. Another approach is using subroutines: FOR /l %%x IN (1,1,10) DO CALL :Test GOTO :EOF :Test AutomatedTest.exe cip.log ECHO %ERRORLEVEL% GOTO :EOF Yet another approach is to use IF ERRORLEVEL.

Categories : Windows

Getting return values in Python C API
Unfortunately PyRun_SimpleString() is too simple. If you want a result back then you need to use PyRun_String{,Flags}().

Categories : Python

how to return many values in mysql_fetch_array php
Try this: return $run[$field_one] . " " . $run[$field_two]; BTW you have to change your query to: "SELECT {$field_one}, {$field_two} FROM users WHERE user_id={$id}" Take a look at this for examples: http://php.net/manual/en/function.mysql-fetch-array.php

Categories : PHP

Cannot return the values of forms
First your return statement inside show_dropdown_row will not provide you with the date you want. That function will run only once when user request for the page. So instead of $name1,$name2 and $name3 in your get_dropdown_options function you should put values like. day,month and year as names for your select elements. When submiting your form at on your php script you should catch those value using post or get. like. $dates=$_POST['year']."-".$_POST['month']."-".$_POST['day'];

Categories : PHP

T-SQL function does not return all values
CREATE FUNCTION [dbo].[fnGetMemberNames] (@MEMBERSHIPID VARCHAR(100)) RETURNS VARCHAR(max) BEGIN DECLARE @name_to_return AS VARCHAR(max); SET @name_to_return = NULL; SELECT @name_to_return = ISNULL(@name_to_return,'') + (C.TITLE + ' ' + C.FIRSTNAME + ' ' + C.SURNAME) + Char(13) + Char(10) FROM CONTACT C LEFT JOIN MEMBERSHIP M ON C.SERIALNUMBER=M.SERIALNUMBER WHERE M.MEMBERSHIPID=@MEMBERSHIPID; RETURN @name_to_return ; END;

Categories : SQL

How do I return the sum of all values in an array?
Return a value from function. function amountTotal(amount) { var total = 0; for (i = 0; i < amount.length; ++i) { total += amount[i]; // add each element in an array to total } return total;// return sum of elements in array }

Categories : Javascript

How to return a value from a range of values
If I understood the question correctly, some nested IFs would do like (assuming input in A4 and the ranges like in the table): =IF(AND(A4>B1,A4<B2),B3,IF(AND(A4>C1,A4<C2),C3,... For more complex (meaning longer) tables you could also use a "helper" column (Column D): IF(AND($A$4>B1,$A$4<B2),B3,"") "drag" this down to copy it and then sum the column to get the result. All a bit of a mess, but I can't think of any more elegant solution using excel formulas.

Categories : Excel

cannot return the exact values in php
Problem is here... function checkLogin($user_id, $upassword) //passing $upassword not $password You pass in $upassword but then dont use it, instead you use..just $password $sql = "SELECT * FROM users WHERE user_id = $user_id AND password = '$password'"; Change to... $sql = "SELECT * FROM users WHERE user_id = $user_id AND password = '$upassword'"; Simple overlooked syntax error :)

Categories : PHP



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