OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [for.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2009 The Go Authors. All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
package main
8
 
9
func assertequal(is, shouldbe int, msg string) {
10
        if is != shouldbe {
11
                print("assertion fail", msg, "\n")
12
                panic(1)
13
        }
14
}
15
 
16
func main() {
17
        var i, sum int
18
 
19
        i = 0
20
        for {
21
                i = i + 1
22
                if i > 5 {
23
                        break
24
                }
25
        }
26
        assertequal(i, 6, "break")
27
 
28
        sum = 0
29
        for i := 0; i <= 10; i++ {
30
                sum = sum + i
31
        }
32
        assertequal(sum, 55, "all three")
33
 
34
        sum = 0
35
        for i := 0; i <= 10; {
36
                sum = sum + i
37
                i++
38
        }
39
        assertequal(sum, 55, "only two")
40
 
41
        sum = 0
42
        for sum < 100 {
43
                sum = sum + 9
44
        }
45
        assertequal(sum, 99 + 9, "only one")
46
 
47
        sum = 0
48
        for i := 0; i <= 10; i++ {
49
                if i % 2 == 0 {
50
                        continue
51
                }
52
                sum = sum + i
53
        }
54
        assertequal(sum, 1+3+5+7+9, "continue")
55
 
56
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.