diff --git a/golang/tuckers_go/08_for/for_02/for-02.go b/golang/tuckers_go/08_for/for_02/for-02.go new file mode 100644 index 0000000..57ab8fd --- /dev/null +++ b/golang/tuckers_go/08_for/for_02/for-02.go @@ -0,0 +1,27 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + stdin := bufio.NewReader(os.Stdin) + for { + fmt.Println("입력하세요.") + var number int + _, err := fmt.Scanln(&number) + if err != nil { + fmt.Println("숫자를 입력하세요.") + + stdin.ReadString('\n') + continue + } + fmt.Printf("입력하신 숫자는 %d 입니다.\n", number) + if number%2 == 0 { + break + } + } + fmt.Println("for문이 종료됐습니다.") +} diff --git a/golang/tuckers_go/08_for/for_03/for-03.go b/golang/tuckers_go/08_for/for_03/for-03.go new file mode 100644 index 0000000..c0843fb --- /dev/null +++ b/golang/tuckers_go/08_for/for_03/for-03.go @@ -0,0 +1,12 @@ +package main + +import "fmt" + +func main() { + for i := 0; i < 3; i++ { + for j := 0; j < 5; j++ { + fmt.Print("*") + } + fmt.Println() + } +} diff --git a/golang/tuckers_go/08_for/for_04/for-04.go b/golang/tuckers_go/08_for/for_04/for-04.go new file mode 100644 index 0000000..eb00260 --- /dev/null +++ b/golang/tuckers_go/08_for/for_04/for-04.go @@ -0,0 +1,12 @@ +package main + +import "fmt" + +func main() { + for i := 0; i < 5; i++ { + for j := 0; j < i+1; j++ { + fmt.Print("*") + } + fmt.Println() + } +} diff --git a/golang/tuckers_go/08_for/for_05/for-05.go b/golang/tuckers_go/08_for/for_05/for-05.go new file mode 100644 index 0000000..ed90299 --- /dev/null +++ b/golang/tuckers_go/08_for/for_05/for-05.go @@ -0,0 +1,23 @@ +package main + +import "fmt" + +func main() { + dan := 2 + b := 1 + for { + for { + fmt.Printf("%d * %d = %d\n", dan, b, dan*b) + b++ + if b == 10 { + break + } + } + b = 1 + dan++ + if dan == 10 { + break + } + } + fmt.Println("for문이 종료되었습니다.") +} diff --git a/golang/tuckers_go/08_for/for_06/for-06.go b/golang/tuckers_go/08_for/for_06/for-06.go new file mode 100644 index 0000000..a887332 --- /dev/null +++ b/golang/tuckers_go/08_for/for_06/for-06.go @@ -0,0 +1,21 @@ +package main + +import "fmt" + +func main() { + a := 1 + b := 1 + found := false + for ; a <= 9; a++ { + for b = 1; b <= 9; b++ { + if a*b == 45 { + found = true + break + } + } + if found { + break + } + } + fmt.Printf("%d * %d = %d\n", a, b, a*b) +} diff --git a/golang/tuckers_go/08_for/for_07/for-07.go b/golang/tuckers_go/08_for/for_07/for-07.go new file mode 100644 index 0000000..2f06be8 --- /dev/null +++ b/golang/tuckers_go/08_for/for_07/for-07.go @@ -0,0 +1,18 @@ +package main + +import "fmt" + +func main() { + a := 1 + b := 1 + +OuterFor: + for ; a <= 9; a++ { + for b = 1; b <= 9; b++ { + if a*b == 45 { + break OuterFor + } + } + } + fmt.Printf("%d * %d = %d\n", a, b, a*b) +} diff --git a/golang/tuckers_go/08_for/for_08/for-08.go b/golang/tuckers_go/08_for/for_08/for-08.go new file mode 100644 index 0000000..827663d --- /dev/null +++ b/golang/tuckers_go/08_for/for_08/for-08.go @@ -0,0 +1,25 @@ +package main + +import "fmt" + +func find45(a int) (int, bool) { + for b := 1; b <= 9; b++ { + if a*b == 45 { + return b, true + } + } + return 0, false +} + +func main() { + a := 1 + b := 0 + + for ; a <= 9; a++ { + var found bool + if b, found = find45(a); found { + break + } + } + fmt.Printf("%d * %d = %d\n", a, b, a*b) +}