Skip to content

Commit e3b7db2

Browse files
committed
Add loops.WhileLoop
1 parent bc1d724 commit e3b7db2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

examples/basic/loops/examples.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func NewRegister() mapping.Register {
1515
func (r *register) Regist(m mapping.ExampleMapping) {
1616
m["loops_basic_for_loop"] = BasicForLoop
1717
m["loops_basic_foreach"] = BasicForeach
18+
m["loops_while_loop"] = WhileLoop
1819
m["loops_channel_loop"] = ChannelLoop
1920
m["loops_slice_loop"] = SliceLoop
2021
m["loops_map_loop"] = MapLoop

examples/basic/loops/while_loop.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package loops
2+
3+
import (
4+
"github.com/devlights/gomy/output"
5+
)
6+
7+
// WhileLoop は、GoでのWhileループについてのサンプルです.
8+
func WhileLoop() error {
9+
// Go には、ループはすべて for で記載することになっている。
10+
// 他の言語にある while () {} は提供されていない。
11+
count := 5
12+
for count > 0 {
13+
output.Stdoutl("[count]", count)
14+
count -= 1
15+
}
16+
17+
return nil
18+
}

0 commit comments

Comments
 (0)