pub enum ForInit {
Decl(Variable),
Expr(Expr),
}Expand description
Represents a for loop in C, which consists of initialization, condition, step expressions, and a body block of statements.
A for loop provides a compact way to iterate with a counter or other form of state that is initialized before the loop, checked before each iteration, and updated after each iteration.
§C Syntax
for (initialization; condition; step) {
// loop body statements
}Each of the three expressions (initialization, condition, step) is optional.
§Example Usage
// Create a for loop that counts from 0 to 9
let for_loop = For::new()
.init(expr!("int i = 0"))
.cond(expr!("i < 10"))
.step(expr!("i++"))
.body(Block::new()
.statement(Statement::expr(expr!("process(array[i])")))
.build())
.build();The initialization clause of a for loop.
C allows the first clause of a for to be either a declaration
(for (int i = 0; ...)) or an ordinary expression (for (i = 0; ...)).
These are genuinely different grammatical categories, so they get distinct
variants here rather than smuggling a declaration through the expression
type.
Variants§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ForInit
impl RefUnwindSafe for ForInit
impl Send for ForInit
impl Sync for ForInit
impl Unpin for ForInit
impl UnsafeUnpin for ForInit
impl UnwindSafe for ForInit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more