Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "os"
- )
- func main() {
- x := 11
- if x > 10 { // Corretto
- fmt.Println("x is greater than 10")
- } else {
- fmt.Println("x is lower than 2")
- }
- // Errato
- // if (x > 10) {
- // fmt.Println("x is greater than 10")
- // }
- if x := getData(); x > 10 {
- fmt.Println(x * 2)
- }
- lingua := "Spagnolo"
- switch lingua {
- case "Italiano":
- fmt.Println("Salve!")
- case "Inglese", "Inglese US", "Inglese BT":
- fmt.Println("Wellcome!")
- default:
- fmt.Println("Lingua non supportata")
- }
- coefficiente := 7
- switch coefficiente % 5 {
- case 0:
- //istruzioni
- case 2:
- //istruzioni
- fallthrough
- case 3:
- //istruzioni
- case 4:
- //istruzioni
- }
- var persona Utente = Insegnante{"fcamuso", "Informatica"}
- switch v := persona.(type) {
- case Studente:
- fmt.Printf("Studente: %s, classe: %s\n", v.nome, v.classe)
- case Insegnante:
- fmt.Printf("Insegnante: %s, materia: %s\n", v.nome, v.materia)
- default:
- fmt.Println("Utente sconosciuto")
- }
- for i := 0; i < 10; i++ {
- fmt.Println(i)
- file, _ := os.Open("main.go")
- defer file.Close()
- scanner := bufio.NewScanner(file)
- // "while scanner.Scan() { ... }"
- for scanner.Scan() {
- riga := scanner.Text()
- fmt.Println(riga)
- }
- var scelta int
- for {
- // Corpo del ciclo: viene eseguito almeno una volta
- fmt.Println("Menu:")
- fmt.Println("1. Opzione uno")
- fmt.Println("2. Opzione due")
- fmt.Println("0. Esci")
- fmt.Print("Scegli un'opzione: ")
- fmt.Scanln(&scelta)
- //switch in base a scelta ...
- if scelta == 0 {
- break // questo esce dal ciclo for
- }
- fmt.Println() // riga vuota tra un ciclo e l’altro
- }
- }
- }
- //y = x > 0 ? -x : 2*x;
- // Interfaccia comune
- type Utente interface {
- Nome() string
- }
- // Tipo Insegnante
- type Insegnante struct {
- nome string
- materia string
- }
- func (i Insegnante) Nome() string {
- return i.nome
- }
- // Tipo Studente
- type Studente struct {
- nome string
- classe string
- }
- func (s Studente) Nome() string {
- return s.nome
- }
- func getData() int { return 900 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement