How to return all value out the for loop in golang [closed] - list

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
In python I can return how value what I append in the array
valuesinPy= []
for i range(len(value)) :
valuesinPy.append(value[i])
return valuesinPy
It's able to return all value I want to append in golang
valueappend =make(map[strig]string)
for i :=range value{
valueappend['abs']=value[i]
}
return valueappend
it's all same
But the value return same I got confused
Problem fix
I use the map [string]interface{}{} I less one struct of slice
valueappend:=map[string]interface{}{}
for i :=range value{
valueappend= append(valueappend, map[string]interface{}{
"valueIwant append" value[i] :
}
}
return valueappend

One issue I can see is that the key you are using is same in all iterations of the loop
valueappend['abs']=value[i]
This will overwrite all previous values and you will only have the last one in the loop be saved. In the end you will get a map with just one value. I'm guessing that's not what you want here. Use can use a unique key for each iteration as follows, or something else along the same line
for i := range value {
valueappend[i]=value[i]
}
#范紀予 please add more info and clarify what you are trying to achieve here.

You'll probably need to change the value of the map each time you go through the loop, or else every value from value[i] will keep writing to that same field in the map, leaving with the last value of i as your only value in the map

Related

How can I determine a state with a given zip code in Stata? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Currently, my line of code is really long and I was curious to know if there was a more efficient way of doing this.
As Nick has pointed out your question is missing most of the information that would make it answerable. Please read more here, and add more information to your question.
In the meantime, a useful approach is to merge your zipcode data with a dataframe (or dataset) with the state-zipcode link in it.
* first you need to get the zipcode data from somewhere.
* Here is one way:
!wget "https://www2.census.gov/geo/docs/maps-data/data/rel/zcta_county_rel_10.txt"
* now put this data in a frame
frame create zctaFrame
frame zctaFrame{
import delimited "zcta_county_rel_10.txt"
}
* now I'm making up a dataset (share some of yours with dataex from ssc
input str10 name zip
"sam" 55901
"sasha" 84101
"saul" 84111
end
frlink 1:1 zip, frame(zctaFrame zcta5)
frget state, from(zctaFrame)
If this doesn't match what you're trying to do, please add more detail to the question.

Stepfunction map with condition [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there is any possibility to run the was step function map Iterator based on the condition Am going to invoke the lambda and based on the result I have to choose the input item of the iteration meaning if there is an array of 0-3 items once the first item executes with lambda then based on the result it should execute 1st index or 2nd index item.
The other option is to create a while loop like this:
Set a variable to track your index (pos = 0)
Do whatever you want to do inside your iteration also you could use some condition, if you want to process each item conditionally
increase your index ( pos++)
If your index is less that your items count go to step1.
This way you have access to the result of previous iteration, so you can fine tune your condition.

Struggling with Inventory system on C++ Game [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
So I am having problems when adding a quantity to an item. For example, the item Fist has a quantity of 1 and id 1. In the void addQuantity(int id, int quantity) function, i "did it" so when you type addQuantity(1, 1) for example, the item fist (which has rarity 1) will get quantity 2 but it just doesn't do anything. Can you guys help me fix it? I just need a working addQuantity, setQuantity and removeQuantity function.
Code: https://hastebin.com/itacijacur.cpp
The code that addQuantity executes is:
this->inventoryVec[id].quantity += quantity;
Here, you are using id as the index within inventoryVec. That's not the same as the id of the Item. In the scenario you have set up in your code, the index of the "fist" Item is actually 0, since it is the one and only Item added to the vector.
If you really want the addQuantity method to access items by their ID numbers, it would need to loop through the inventoryVec vector to search for an item whose ID number matches the id parameter of the method.
You are accessing the index of the vector as index 1, you are wanting to scan the vector and try and find the item that has the correct id, if found then you want to make the change to the item.
Change your addQuantity function to
void Inventory::addQuantity(int id, int quantity)
{
for (int i = 0; i < inventoryVec.size(); i++)
{
if (inventoryVec.at(i).getID() == id)
{
inventoryVec.at(i).quantity += quantity;
}
}
}
This will cycle through the vector and find the correct item, you were assuming the items index was equal to its ID.
Hope this helps, any questions just ask.

ABAP free internal table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
The answer to the question below is given as 2. Why does refresh delete only the first row? Is it not expected that it deletes all rows of an internal table?
What will be output by the following code?
DATA: BEGIN OF itab OCCURS 0, fval type i, END OF itab.
itab­-fval = 1. APPEND itab.
itab­-fval = 2. APPEND itab.
REFRESH itab.
WRITE: /1 itab­-fval.
A: 1
B: 2
C: blank
D: 0
Answer: B
If the code did not contain any syntax errors, e.g. the missing '-' when assigning the value 2 and when writing the value, then B is the correct answer but not for the reason you state. It is not that the REFRESH only removes the first line from the table, it is because REFRESH does not clear the header line of the table. So after the REFRESH the header line still has the latest assigned value which is 2. This can be easily ascertained when running the program in the debugger.
Note that the use of internal table with header lines is obsolete, as mentioned in SAP help.
You can use a clear command to clear the header line.
REFRESH itab.
CLEAR itab.

IF ELSE in display column tag in struts2 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Hi i am using display column tag in struts2.
And want to format row on basis of data...
For example column hs boolean value.
If value is true i want display row in red font.
else in black font.
So how can i implement if else condition in display column tag in struts2?
I have check on net, bt solutions given ar
Can anyone give me code example for the same???
thanks in advance.
Please check this and link for Example
<s:if test="%{column ==true}">
// do stuff to change row color
</s:if>
<s:else>
// do stuff to change black font
</s:else>