Junior — Middle
Could you explain what is meant by the term 'function' in programming?
sobes.tech AI
Answer from AI
In programming, a function is a named block of code that performs a specific task and can accept input data (parameters), as well as return a result. Functions help structure the program, reuse code, and simplify understanding.
Example of a function in Swift (iOS):
func greet(name: String) -> String {
return "Hello, \(name)!"
}
let message = greet(name: "Alexey")
print(message) // Outputs: Hello, Alexey!
Here, the greet function takes a name and returns a greeting message.