Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

For

for statement represent repetition. Loop variable is placed before in keyword, and range is placed after it.

break can be used to break the loop.

module ModuleA {
    var a: logic<10>;

    always_comb {
        for i in 0..10 {
            a = i;

            if i == 5 {
                break;
            }
        }
    }
}

You can iterate the loop in descending order by putting rev keyword after in keyword.

module ModuleA {
    var a: logic<10>;

    always_comb {
        for i in rev 0..10 {
            a = i;

            if i == 5 {
                break;
            }
        }
    }
}