Skip to content

Commit

Permalink
golang for done
Browse files Browse the repository at this point in the history
  • Loading branch information
nahyunsama committed Jul 15, 2024
1 parent 3815972 commit 6f4b389
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
27 changes: 27 additions & 0 deletions golang/tuckers_go/08_for/for_02/for-02.go
Original file line number Diff line number Diff line change
@@ -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문이 종료됐습니다.")
}
12 changes: 12 additions & 0 deletions golang/tuckers_go/08_for/for_03/for-03.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
12 changes: 12 additions & 0 deletions golang/tuckers_go/08_for/for_04/for-04.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
23 changes: 23 additions & 0 deletions golang/tuckers_go/08_for/for_05/for-05.go
Original file line number Diff line number Diff line change
@@ -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문이 종료되었습니다.")
}
21 changes: 21 additions & 0 deletions golang/tuckers_go/08_for/for_06/for-06.go
Original file line number Diff line number Diff line change
@@ -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)
}
18 changes: 18 additions & 0 deletions golang/tuckers_go/08_for/for_07/for-07.go
Original file line number Diff line number Diff line change
@@ -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)
}
25 changes: 25 additions & 0 deletions golang/tuckers_go/08_for/for_08/for-08.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 6f4b389

Please sign in to comment.