From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/SYNTAX/while.html | 160 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 reference/C/SYNTAX/while.html (limited to 'reference/C/SYNTAX/while.html') diff --git a/reference/C/SYNTAX/while.html b/reference/C/SYNTAX/while.html new file mode 100644 index 0000000..ef083f9 --- /dev/null +++ b/reference/C/SYNTAX/while.html @@ -0,0 +1,160 @@ + + +The WHILE keyword. + + + +
+

The WHILE keyword.

+
+The while keyword is related to do +and for. Its purpose is to repeatedly execute +a block of statements. Here is +an example : + +

+

+ + + + +
+
+
+        main()
+        {
+            int i=5;
+
+            while(--i)
+            {
+                printf(" i is %d\n", i);
+            }
+        }
+
+
+
+

+ +The expression i-- is evaluated and if its +true the statements in the +block are executed. +The loop continues until the expression is false (zero). +The result will look like this: + +

+

+ + + + +
+
+                
+                i is 4
+                i is 3
+                i is 2
+                i is 1
+
+
+
+

+ +It is important to note that the statements +on a while will not get executed if the first evaluation of the +expression is FALSE. If you do not want this to happen you may prefer +to use the do statement. + +


+

+Now consider the next example. + +

+

+ + + + +
+
+
+        main()
+        {
+            int i=5;
+
+            while(--i);
+            {
+                printf(" i is %d\n", i);
+            }
+        }
+
+
+
+ + +The result will look like this: + + +

+

+ + + + +
+
+
+                i is 0
+
+
+
+ +

+This is because of the ; on the end of the while +statement which means the while will loop (executing NULL statements) +until i is zero. Execution will then continue down the program +(to the printf). +

+ +


+

Examples:

+ +o +Basic while. +
+ +
+

See also:

+ + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + -- cgit v1.2.3-54-g00ecf 398acbf4b675713b76'/>
context:
space:
mode:

Diffstat (limited to 'Documentation')