Skip to content

Add to loop size array in data-types.md#41

Open
furidosu wants to merge 2 commits intoWerWolv:masterfrom
furidosu:patch-3
Open

Add to loop size array in data-types.md#41
furidosu wants to merge 2 commits intoWerWolv:masterfrom
furidosu:patch-3

Conversation

@furidosu
Copy link
Copy Markdown
Contributor

No description provided.

u8 string[while(std::mem::read_unsigned($, 1) != 0xFF)] @ 0x00;
```

For more complex conditions, combine an array to `eof` with a struct containing `if` statements. Using `continue` would move on to the next array item of the loop; using `break` would stop the loop and the growing of the array. See also the [pattern control flow](control-flow.md#pattern-control-flow).
Copy link
Copy Markdown
Contributor

@C3pa C3pa Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For more complex conditions, combine an array to `eof` with a struct containing `if` statements. Using `continue` would move on to the next array item of the loop; using `break` would stop the loop and the growing of the array. See also the [pattern control flow](control-flow.md#pattern-control-flow).
For more complex conditions, set the array to grow until `eof` with a struct containing `if` statements. Using `continue` will move on to the next array item of the loop; using `break` will stop the loop and the growing of the array. See also the [pattern control flow](control-flow.md#pattern-control-flow).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what you are referring to by "Using continue would move on to the next array item of the loop; using break would stop the loop and the growing of the array."

If I am not mistaken, the following syntax: Command command_list[while(!std::mem::eof())] @ 0x00; doesn't permit using break or continue keywords since you can't specify the loop body.

Copy link
Copy Markdown
Contributor

@paxcut paxcut Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow control is applied to the structs, not the array so for example you can do

enum Action : u8 {
     Stop,
    Skip,
    Read
};
struct Command {
    Action action;
    if (action == Action::Stop)
          break;
   if (action== Action::Skip)
      continue;
    if (action == Action::Read)
       u8 data[5];
};
Command command_list[while(!std::mem::eof())] @ 0x00;

Maybe the example code should be simpler and better formatted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants