go routine example 1

This commit is contained in:
Mert Gör 🇹🇷 2024-01-21 19:18:44 +03:00
parent 25081c4c83
commit 9e917844ff
Signed by: hwpplayer1
GPG Key ID: 03E547D043AB6C8F
2 changed files with 11 additions and 3 deletions

View File

@ -1,15 +1,20 @@
package goroutines
import "fmt"
import (
"fmt"
"time"
)
func EvenNumber() {
for i := 0; i <= 10; i+=2 {
fmt.Println("Even Number : ", i)
time.Sleep(1 * time.Second)
}
}
func OddNumber() {
for i := 1; i <= 10; i+=2 {
fmt.Println("Odd Number : ", i)
time.Sleep(1 * time.Second)
}
}

View File

@ -13,6 +13,7 @@ import (
"golesson/slices"
"golesson/structs"
"golesson/variables"
"time"
)
func main() {
@ -57,6 +58,8 @@ func main() {
structs.Demo1()
structs.Demo2()
goroutines.EvenNumber()
goroutines.OddNumber()
go goroutines.EvenNumber()
go goroutines.OddNumber()
time.Sleep(5 * time.Second)
fmt.Println("Main ended")
}