M
M
Medovochka2021-09-29 18:39:42
Swift
Medovochka, 2021-09-29 18:39:42

How to repeat identical actions with different parameters in Swift?

I am just starting to study data types, tell me please, is it possible somehow to make repeated transformations of data types shorter, and not so many lines?

In the first case, round each value and then only add.
And in the second, print only the values ​​​​after the decimal point, and then add them.

And I want to understand how this can be done more briefly (if it is real in Swift).
61548932ec85c271239432.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
briahas, 2021-09-29
@briahas

If I understand your question correctly, then you can create a method that will accept an array of numbers and then perform some actions on the elements of the array in a loop: add or, first, truncate, and then add ... whatever.

A
Alexander Prokhorovich, 2021-09-29
@alexgp13

Judging by the formulation of questions, you have not yet read up to the cycles. Read what it is, cycles and there is a solution to your problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question