Skip to content

Commit f94e051

Browse files
author
Ashwin Hegde
committed
Merge pull request #20 from hegdeashwin/develop
Develop
2 parents 6922472 + 95f50ce commit f94e051

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

codes/ch4_looping/break.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import "fmt";
4+
5+
func main() {
6+
7+
/**
8+
* `for` loop
9+
*
10+
* for [assignment]; [conditions]; [increment/decrement] { ... }
11+
*/
12+
for i := 0; i < 10; i++ {
13+
14+
/**
15+
* loop will break; once i is greater than 4
16+
*/
17+
if i > 4 {
18+
break;
19+
}
20+
21+
fmt.Println("i =", i)
22+
}
23+
24+
}

codes/ch4_looping/continue.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import "fmt";
4+
5+
func main() {
6+
7+
/**
8+
* `for` loop
9+
*
10+
* for [assignment]; [conditions]; [increment/decrement] { ... }
11+
*/
12+
for i := 0; i < 10; i++ {
13+
14+
/**
15+
* loop will continue; once i is greater than 5
16+
*/
17+
if i > 5 {
18+
continue;
19+
}
20+
21+
/**
22+
* this will get skipped once i is greate then 5;
23+
*/
24+
fmt.Println("i =", i)
25+
}
26+
27+
}

codes/ch4_looping/for.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import "fmt";
4+
5+
func main() {
6+
7+
/**
8+
* `for` loop
9+
*
10+
* for [assignment]; [conditions]; [increment/decrement] { ... }
11+
*/
12+
for i := 0; i < 10; i++ {
13+
fmt.Println("i =", i)
14+
}
15+
16+
}

codes/ch4_looping/range.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import "fmt";
4+
5+
type Profile struct {
6+
name string
7+
role string
8+
}
9+
10+
func main() {
11+
12+
slice := []Profile {
13+
{"Ashwin", "Sr. Fullstack Engineer"},
14+
{"Kumar", "Sr. Engineering Manager"},
15+
{"Saju", "Sr. Solution Architect"},
16+
{"Ajay", "Sr. Solution Architect"}, // comma is needed here
17+
}
18+
19+
/**
20+
* _ is index; we are not using it; thus replacing with _
21+
*/
22+
for _, employee := range slice {
23+
fmt.Println("Profile: " + employee.name + " (" + employee.role + ")" )
24+
}
25+
26+
}

codes/ch4_looping/while.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import "fmt";
4+
5+
func main() {
6+
7+
/**
8+
* There is no while loop in Go-lang;
9+
* but we can use `for` loop to behave like `while` loop.
10+
*/
11+
i := 0;
12+
for i < 10 {
13+
fmt.Println("i =", i)
14+
15+
i++
16+
}
17+
18+
}

codes/session-4/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)