8a859afd58
remove "unnecessary if statement" error this "depends on compile variable" code is too hard to validate, and has false negatives. not worth it right now. std.str removed, instead use std.mem. std.mem.eql and std.mem.sliceEql merged and do not require explicit type argument.
34 lines
663 B
Zig
34 lines
663 B
Zig
const std = @import("std");
|
|
const assert = std.debug.assert;
|
|
const mem = std.mem;
|
|
|
|
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()
|
|
}
|
|
|
|
fn forLoopWithPointerElemVar() {
|
|
@setFnTest(this);
|
|
|
|
const source = "abcdefg";
|
|
var target: [source.len]u8 = undefined;
|
|
@memcpy(&target[0], &source[0], source.len);
|
|
mangleString(target);
|
|
assert(mem.eql(target, "bcdefgh"));
|
|
}
|
|
fn mangleString(s: []u8) {
|
|
for (s) |*c| {
|
|
*c += 1;
|
|
}
|
|
}
|