File: for.txt

package info (click to toggle)
colobot 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 415,532 kB
  • sloc: cpp: 129,246; ansic: 8,872; python: 2,158; sh: 672; awk: 91; xml: 35; makefile: 31
file content (53 lines) | stat: -rw-r--r-- 1,554 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
\b;Instruction \c;for\n;
Syntax:
\s;\c;for ( before ; condition ; end )
\s;{
\s;	\n;Instructions ...\c;
\s;}
\n;
This instruction allows you to execute a certain number of times the instructions contained in the \l;block\u cbot\bloc;.

\t;\c;before\n;
This set of instructions is executed before the first loop instance.

\t;\c;condition\n;
This \l;condition\u cbot\cond; determines if another instance of the loop must be executed. It is tested before every instance of the loop. 

\t;\c;end\n;
This set of instructions is executed at the end of every instance of the loop. 

Example: count from 1 to 4
\c;\s;\c;for ( i = 1 ; i <= 4 ; i++ )
\s;{
\s;	message(i) ;
\s;}
\n;
The following example is strictly equivalent to a \c;for\n;-loop, but it uses the instruction \c;\l;while\u cbot\while;\n;:
\s;\c;before;
\s;while ( condition )
\s;{
\s;	\n;Instructions ...\c;
\s;	end;
\s;}
\n;
\t;Attention
Do not put a \l;semicolon\u cbot\term; at the end of the line \c;for ( )\n;.

The instructions \c;\l;break\u cbot\break;\n; and \c;\l;continue\u cbot\continue;\n; can be useful inside a block following the instruction \c;for \n;.

\t;Executing more instructions
In the \c;before\n; and \c;end\n; part of a \c;for\n; loop you can specify more than one instruction by using comma. Example:
\c;
\s;int i = 0;
\s;int j;
\s;for (i++, j = 2; i < 3 && j > 0; i++, j--)
\s;{
\s;    message(i);
\s;    message(j);
\s;}
\n;
The output of the above code is \c;1 2 2 1\n;.

\t;See also
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.