2017-01-05 08:57:48 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const assert = std.debug.assert;
|
|
|
|
const str = std.str;
|
|
|
|
|
2016-12-19 05:41:37 +00:00
|
|
|
fn continueInForLoop() {
|
|
|
|
@setFnTest(this);
|
|
|
|
|
|
|
|
const array = []i32 {1, 2, 3, 4, 5};
|
|
|
|
var sum : i32 = 0;
|
|
|
|
for (array) |x| {
|
|
|
|
sum += x;
|
|
|
|
if (x < 3) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sum != 6) @unreachable()
|
|
|
|
}
|
2016-12-26 08:44:59 +00:00
|
|
|
|
|
|
|
fn forLoopWithPointerElemVar() {
|
|
|
|
@setFnTest(this);
|
|
|
|
|
|
|
|
const source = "abcdefg";
|
|
|
|
var target: [source.len]u8 = undefined;
|
|
|
|
@memcpy(&target[0], &source[0], source.len);
|
|
|
|
mangleString(target);
|
2017-01-05 08:57:48 +00:00
|
|
|
assert(str.eql(target, "bcdefgh"));
|
2016-12-26 08:44:59 +00:00
|
|
|
}
|
|
|
|
fn mangleString(s: []u8) {
|
|
|
|
for (s) |*c| {
|
|
|
|
*c += 1;
|
|
|
|
}
|
|
|
|
}
|