본 게시글은 Golang Tutorial for Beginners | Full Go Course을 학습하며 작성한 개인 노트입니다.
an indefinite loop
for {
// code
}
// code
firstNames := []string{}
for _, booking := range bookings {
var names = strings.Fields(booking)
firstNames = append(firstNames, names[0])
}
strings.Fields(string value)
splits the string with white space as separator & returns a slice with split elements
_
if remainingTickets == 0 {
// end program
fmt.Println("Our conference is booked out. Come back next year.")
break // ends the loop
}
if userTickets > int(remainingTickets) {
fmt.Printf("We only have %v tickets remaining, so you can't book %v tickets\n", remainingTickets, userTickets)
continue
}
if
and else
possiblevar isValidName bool = len(firstName) >= 2 && len(lastName) >= 2
isValidEmail := strings.Contains(email, "@")
default
- if none of the specificed conditions are truecity := "London"
switch city {
case "New York":
// code
case "Singapore":
//code
default:
// code
}