@kjk1/

book array indexes

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.7390558521349104","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"CnBhY2thZ2UgbWFpbgoKaW1wb3J0ICJmbXQiCgpmdW5jIG1haW4oKSB7CgkvLyA6c2hvdyBzdGFydAoJdmFyIGFycmF5ID0gWzZdaW50ezEsIDIsIDMsIDQsIDUsIDZ9CgoJLy8gZG9lc24ndCB3b3JrOiBpbnZhbGlkIGFycmF5IGluZGV4IC0xIChpbmRleCBtdXN0IGJlIG5vbi1uZWdhdGl2ZSkKCS8vIGZtdC5QcmludGxuKGFycmF5Wy00Ml0pCglmbXQuUHJpbnRsbihhcnJheVswXSkgLy8gPiAxCglmbXQuUHJpbnRsbihhcnJheVsxXSkgLy8gPiAyCglmbXQuUHJpbnRsbihhcnJheVsyXSkgLy8gPiAzCglmbXQuUHJpbnRsbihhcnJheVszXSkgLy8gPiA0CglmbXQuUHJpbnRsbihhcnJheVs0XSkgLy8gPiA1CglmbXQuUHJpbnRsbihhcnJheVs1XSkgLy8gPiA2CgkvLyBkb2Vzbid0IHdvcms6IGludmFsaWQgYXJyYXkgaW5kZXggNiAob3V0IG9mIGJvdW5kcyBmb3IgNi1lbGVtZW50IGFycmF5KQoJLy9mbXQuUHJpbnRsbihhcnJheVs2XSkKCS8vIDpzaG93IGVuZAp9"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package main

import "fmt"

func main() {
	// :show start
	var array = [6]int{1, 2, 3, 4, 5, 6}

	// doesn't work: invalid array index -1 (index must be non-negative)
	// fmt.Println(array[-42])
	fmt.Println(array[0]) // > 1
	fmt.Println(array[1]) // > 2
	fmt.Println(array[2]) // > 3
	fmt.Println(array[3]) // > 4
	fmt.Println(array[4]) // > 5
	fmt.Println(array[5]) // > 6
	// doesn't work: invalid array index 6 (out of bounds for 6-element array)
	//fmt.Println(array[6])
	// :show end
}