zig/test/cases/for.zig

34 lines
663 B
Zig
Raw Normal View History

2017-01-05 08:57:48 +00:00
const std = @import("std");
const assert = std.debug.assert;
const str = std.str;
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;
}
}