Statement

To group statements there is a CStatements object

var = CVariable("u32My_var", Cuint32, initial_value=CLiteral(5))
array = CArray("u8My_array", Cuint8, length=10)
statements = CStatements([
    var.declare(),
    array.declare(),

    # Statements can also contain other statements
    CStatements([
        CVariable("u8Var", Cuint8, initial_value=CLiteral(3)).declare()
    ])
])
print(statements.render())
uint32_t u32My_var = 5;
uint8_t u8My_array[10];
uint8_t u8Var = 3;

Declarations include declarations and definitions of variable, function, class… etc but not other statements (if, while, …)

fun = CFunction("my_fun")
declarations = CDeclarations([
    # Declarations include declarations and definitions of variable, function, class... etc
    # But not other statements (if, while, ...)
    fun.declare(),
    fun.define()
])
print(declarations.render())
void 
my_fun(void);
void my_fun(void)
{

}
c_if = CIf(
    CLiteral(True),
    [
        var.declare()
    ]
).ELSE_IF(
    CLiteral(False),
    [
        array.declare()
    ]
).ELSE(
    [
        var.declare()
    ]
)
print(c_if.render())
if (true)
{
	uint32_t u32My_var = 5;
}
else if (false)
{
	uint8_t u8My_array[10];
}
else 
{
	uint32_t u32My_var = 5;
}

Switch

c_switch = CSwitch(
    CExpressionFreeStyle('i'),
    [
        CSwitch.Case(
            CLiteral(1),
            [
                var.declare()
            ]
        ),
        CSwitch.Default(
            [
                array.declare()
            ]
        )
    ]
)
print(c_switch.render())
switch (i)
{
	case 1:
		uint32_t u32My_var = 5;
		break;
	default:
		uint8_t u8My_array[10];
		break;
}

While

c_while = CWhile(
    CExpressionFreeStyle('i < 3'),
    [
        var.declare(),
        CContinue()
    ]
)
print(c_while.render())
while (i < 3)
{
	uint32_t u32My_var = 5;
	continue;
}

Do While

c_do_while = CDoWhile(
    [
        var.declare(),
        CBreak()
    ],
    CLiteral(False)
)
print(c_do_while.render())
do
{
	uint32_t u32My_var = 5;
	break;
}
while (false)

For

c_empty_for = CFor(
    statements=[
        var.declare()
    ]
)
print(c_empty_for.render())
for (;;)
{
	uint32_t u32My_var = 5;
}
c_for = CFor(
    initial=CStatementFreeStyle('i=0'),
    condition=CExpressionFreeStyle('i<10'),
    iteration=CExpressionFreeStyle('i++'),
    statements=[
        var.declare(),
        CReturn(var)
    ]
)
print(c_for.render())
for (i=0; i<10; i++)
{
	uint32_t u32My_var = 5;
	return u32My_var;
}