Un cours pour se lancer dans la programmation avec le langage Go (golang).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 763 B

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package main
  2. import "fmt"
  3. type person struct {
  4. name string
  5. }
  6. var p = person{name: "R Stallman"}
  7. func main() {
  8. p1 := person{name: "Jane Doe"} // ici person definit en global
  9. type person struct {
  10. name string
  11. age int
  12. }
  13. p2 := person{ // ici person en local
  14. name: "John Doe",
  15. age: 27,
  16. }
  17. fmt.Printf("Type de p: %+v\tp1: %v\tp2: %v\n", p, p1, p2)
  18. blocks()
  19. scopes()
  20. shadowing()
  21. }
  22. func blocks() {
  23. i := 10
  24. {
  25. i := 5
  26. fmt.Println(i) // i vaut 5
  27. }
  28. fmt.Println(i) // i vaut 10
  29. }
  30. var y = 100
  31. func scopes() {
  32. x := 10
  33. var z int
  34. {
  35. fmt.Println(x)
  36. y := 15
  37. fmt.Println(y)
  38. z = 20
  39. }
  40. fmt.Println(z)
  41. fmt.Println(y)
  42. }
  43. func shadowing() {
  44. x := 10
  45. {
  46. x := 15
  47. {
  48. x := 20
  49. fmt.Println(x)
  50. }
  51. fmt.Println(x)
  52. }
  53. fmt.Println(x)
  54. }