9.11 Parameters as Variables
All parameters accepted by a function are treated as constants by default. This prevents changes being made to those parameter values within the function code. If changes to parameters need to be made within the function body, therefore, shadow copies of those parameters must be created. The following function, for example, is passed length and width parameters in inches, creates shadow variables of the two values and converts those parameters to centimeters before calculating and returning the area value:
func calcuateArea(length: Float, width: Float) -> Float {
var length = length
var width = width
length = length * 2.54
width = width * 2.54
return length * width
}
print(calcuateArea(length: 10, width: 20))