main
function as your entry point.:=
operator which can infer the type and assign it to a variable at the same time. Using it we can write the same example as above and omit the var
and int
.for
loop.break
keyword, this will print 0 to 4.main
)(p Person)
part. This basically says that the type that can receive this method call is of type Person
and that within that function we want to name that receiver p
.Cat
and Dog
as Eater
s in the printEatResult
function. Notice how we didn't have to do anything to explicitly say that Cats and Dogs implement the Eater interface, the compiler just figured it out because the signature of the eat
function on each of those structs matched the Eater
's version of it.eat
) to end with the name of that method plus er
, so eater
.