loops: break continue


Expected result...
/*
1
2
3
4
6
7
8
9
10
*/

In C++
#include 
using namespace std;

int main() {
    int count = 0;
    while (true) {
        count += 1;
        //end loop if count is greater than 10
        if (count > 10) {
            break;
        }
        //skip 5
        if (count == 5) {
            continue;
        }
        cout << count << endl;
    }
}
In golang...
package main
import (
    "fmt"
    "time"
)

func main() {
    test := 0
    for {
        test += 1
        if test > 10 {
            break
        }
        if test == 5 {
            continue
        }

        fmt.Println(test)
        time.Sleep(300 * time.Millisecond)
    }
}

No comments:

Post a Comment