N
N
nano_e_t_42017-07-28 13:39:15
go
nano_e_t_4, 2017-07-28 13:39:15

How to iterate over a structure in a loop?

Hello everyone
There is a structure with 23 fields, with int64 and float64 types. It is necessary to perform a mathematical operation with each field, plus or minus (depending on the specific user action). How can this be done?
I see it in such a way that there is a function where the structure object and the value to be added are supplied. But I can't figure out how to bypass each field of the strutkra. Let me know if anyone has experienced or knows

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
longclaps, 2017-07-28
@nano_e_t_4

GO is a language with static typing, the type of operands is calculated during compilation, how can it "bypass the structure" to do different (by type of operands) operations? Answer: You will prompt him, with pens, in all 23 cases.

A
Alexander Pavlyuk, 2017-07-28
@pav5000

This can be done through the reflect package, but if you need it, then something is wrong in the architecture of your program and you are trying to transfer the experience of scripting languages ​​to go. Do not do it this way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question