0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

多言語FizzBuzzチャレンジ4日目:Zig

Last updated at Posted at 2022-12-03

これまでのまとめ

本日のお品書き

知名度もあがってきている新星Zig…!

FizzBuzz

Qiitaのコードスペース、Zig対応してくれてますね!

const std = @import("std");

pub fn main() !void {
    var i: u8 = 1;
    // while pattern
    while (i <= 100) : (i += 1) {
        if (i % 15 == 0) {
            std.debug.print("{s}\n", .{"FizzBuzz"});
        } else if (i % 3 == 0) {
            std.debug.print("{s}\n", .{"Fizz"});
        } else if (i % 5 == 0) {
            std.debug.print("{s}\n", .{"Buzz"});
        } else {
            std.debug.print("{}\n", .{i});
        }
    }

    // forでも書けそうだが、forはarrayに対するiterateを想定していそう
    // https://ziglearn.org/chapter-1#for
}
  • 冒頭で次のように宣言すれば、もう少しシュッとprintを呼び出せる。
const print = std.debug.print;
const std = @import("std");
  • forwhileで結構構文が違うんですね?

【参考】コードの作成~コンパイルまで

zig init-exe #実行ファイル用のボイラーテンプレート作成
#edit src/main.zig
zib build run
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?