-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] cpp2 for loops #1063
Comments
That's a good question I should cover somewhere. Here's the quick answer: auto cpp1() {
// Prints: 0123456789
for ( int i = 0; i < 10; ++i ){
std::cout << i;
}
std::cout << "\n";
}
main: () = {
cpp2();
// Prints: 0123456789
(copy i := 0) while i < 10 next i++ {
std::cout << i;
}
std::cout << "\n";
// Same, just my personal whitespace style
(copy i := 0)
while i < 10
next i++ {
std::cout << i;
}
std::cout << "\n";
} Line by line (and why I like being able to write the parts on individual lines):
I should add an example to the docs... I'll keep this open until I do that. Thanks! |
Now added here: https://hsutter.github.io/cppfront/cpp2/functions/#for-while-do-loops Thanks! |
@hsutter You closed this thread but it turns out that your answer left me with more questions! 😅
Anyway, thanks for the quick answer and the amazing work overall |
Moving this to discussions (see #1073), as it seems more appropriate |
Hi! My question is rather simple, but I could not find the answer in the documentation nor in other issues. What is the cpp2 equivalent for:
All the examples in the documentation seem to be range-based for loops, and the closest I could find (which is obviously not the right answer) is:
Thanks for the amazing work!
Best regards,
Alex
The text was updated successfully, but these errors were encountered: