Skip to content

Commit

Permalink
SatCom: labels
Browse files Browse the repository at this point in the history
  • Loading branch information
hexagonrecursion committed Dec 29, 2024
1 parent 910b0dd commit 7c5abee
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
27 changes: 26 additions & 1 deletion help/cbot/E/break.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ Here is an example:
\s; \n;more instructions ...\c;
\s;}
\n;

You can give a loop a label like this:
\s;\c;this_is_a_label: while ( true )
\s;{
\s; \n;Instructions ...\c;
\s;}
\n;
By default when multiple loops are nested inside one another, this instruction affects the innermost loop. If this is not what you want, you can use a label to tell this instruction which loop it should affect:
\s;\c;string result = "";
\s;foo: for(int outer = 0; true; ++outer)
\s;{
\s; result += "A";
\s; for(int inner = 1; inner < 3; ++inner)
\s; {
\s; result += "B";
\s; if(inner == outer)
\s; {
\s; result += "*";
\s; break foo;
\s; }
\s; result += "C";
\s; }
\s; result += "D";
\s;}
\s;result += "E";
\s;message(result); // Prints: ABCBCDAB*E
\n;
\t;See also
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
25 changes: 25 additions & 0 deletions help/cbot/E/continue.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,30 @@ Here is an example:
\n;
The instructions will only be executed for the values of \c;i\n; 1, 2, 4 and 5.

You can give a loop a label like this:
\s;\c;this_is_a_label: while ( true )
\s;{
\s; \n;Instructions ...\c;
\s;}
\n;
By default when multiple loops are nested inside one another, this instruction affects the innermost loop. If this is not what you want, you can use a label to tell this instruction which loop it should affect:
\s;\c;string result = "";
\s;foo: for(int outer = 0; outer < 3; ++outer)
\s;{
\s; result += "A";
\s; for(int inner = 0; inner < 2; ++inner)
\s; {
\s; result += "B";
\s; if(inner == outer)
\s; {
\s; result += "*";
\s; continue foo;
\s; }
\s; result += "C";
\s; }
\s; result += "D";
\s;}
\s;message(result); // Prints: AB*ABCB*ABCBCD
\n;
\t;See also
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.

0 comments on commit 7c5abee

Please sign in to comment.