Skip to content

Commit 2f23bac

Browse files
committed
for-loop
1 parent 06eba1c commit 2f23bac

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

05_loops/loops.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// for looping only "FOR"
2+
package main
3+
import "fmt"
4+
5+
func main(){
6+
//WHILE LOOP FASHION - FOR
7+
i := 1
8+
for i<=3 {
9+
fmt.Println(i)
10+
i=i+1
11+
12+
}
13+
14+
//INFINITE LOOP
15+
/*
16+
for {
17+
println ("1")
18+
}
19+
*/
20+
21+
//FOR LOOP
22+
23+
for i:=0;i<3;i++{
24+
fmt.Println(i)
25+
}
26+
27+
//CONTINUE - AND - BREAK is also used
28+
for i:=0;i<3;i++{
29+
//break - stops the loop
30+
}
31+
32+
33+
for i:=0;i<3;i++{
34+
//continue- current iterations stops
35+
if i=2{
36+
continue //--- 2 will never come
37+
}
38+
39+
}
40+
41+
//RANGE-want to do some thing for some times
42+
for i:= range 3 {
43+
fmt.Println(i)
44+
} //OUTPUT - 1,2
45+
46+
47+
}

0 commit comments

Comments
 (0)