defer

A defer statement defers the execution of a statement until the end of scope.

import "os.odin";

main :: proc() {
    file, _ := os.open("text.txt", os.O_RDONLY, 0);
    // Close file at end of scope
    defer os.close(file);

    // Do whatever with file until end of scope
}

results matching ""

    No results matching ""