|
|
@@ -56,7 +56,7 @@ Semisemi `for` loops have been around for a long time, and are in C. Range-based
|
|
|
|
|
|
For example, here is a basic semisemi:
|
|
|
|
|
|
-```cc
|
|
|
+```c++
|
|
|
for (int i = 0; i < list.size(); ++i) {
|
|
|
printf("List at %d: %s\n", i, list[i].name);
|
|
|
}
|
|
|
@@ -64,7 +64,7 @@ for (int i = 0; i < list.size(); ++i) {
|
|
|
|
|
|
An equivalent semisemi using iterators and the comma operator may look like:
|
|
|
|
|
|
-```cc
|
|
|
+```c++
|
|
|
int i = 0;
|
|
|
for (auto it = list.begin(); it != list.end(); ++it, ++i) {
|
|
|
printf("List at %d: %s\n", i, it->name);
|
|
|
@@ -74,7 +74,7 @@ for (auto it = list.begin(); it != list.end(); ++it, ++i) {
|
|
|
Range-based syntax can be simpler, but can also make it more difficult if there
|
|
|
are multiple pieces of interesting information:
|
|
|
|
|
|
-```cc
|
|
|
+```c++
|
|
|
int i = 0;
|
|
|
for (const auto& x : list) {
|
|
|
printf("List at %d: %s\n", i, x.name);
|
|
|
@@ -253,7 +253,7 @@ section of the semisemi. The inter-loop evaluation of the third section is
|
|
|
important given how it interacts with `continue`. In particular, consider the
|
|
|
loops:
|
|
|
|
|
|
-```cc
|
|
|
+```c++
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
if (i == 1) continue;
|
|
|
printf("%d\n", i);
|