File: while.txt

package info (click to toggle)
colobot 0.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 415,536 kB
  • sloc: cpp: 129,246; ansic: 8,872; python: 2,158; sh: 672; awk: 91; xml: 35; makefile: 31
file content (47 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download | duplicates (13)
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
\b;Instruction \c;while\n;
The instruction \c;while () {}\n; is used to repeat a set of instructions several times.

\b;Basic use
The most frequent use of \c;while\n; consists in repeating a set of instructions again and again. In order to achieve this, write \c;while (true) {}\n; and put the instructions to be repeated in braces \c;{}\n;. As an example, here is a program that repeats again and again the following actions:
o  look for a spider,
o  turn towards it,
o  shoot.
\c;
\s;	while (true)
\s;	{
\s;		item = \l;radar\u cbot\radar;(AlienSpider);
\s;		\l;turn\u cbot\turn;(direction(item.position));
\s;		\l;fire\u cbot\fire;(1);
\s;	}
\n;
Just execute this program once, and it will kill all spiders around it.

\b;For specialists
Syntax :
\s;\c;while ( condition )
\s;{
\s;	\n;Instructions ...\c;
\s;}
\n;
This instruction allows you to perform the instructions inside the \l;block\u cbot\bloc; several times.

Be careful not to confuse the instruction \c;while( ) { }\n; with the instruction \c;\l;do\u cbot\do; { } while( );\n;; the latter tests the condition only after the instructions in the block have been performed a first time. 

\t;\c;condition\n;
The instructions in the block are performed over and over again, as long as the \l;condition\u cbot\cond; is true. 

Here is an example :
\s;\c;int i = 0;
\s;while ( i < 10 )
\s;{
\s;	\n;Instructions ...\c;
\s;	i = i+1;
\s;}
\n;
\t;Attention
Do not put a \l;semicolon\u cbot\term; at the end of the line \c;while ( )\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;while { }\n;.

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