rev 488 - in trunk: docs/tutorial pr/tutorial

SVN User <[email protected]> Fri, 14 May 2004 17:19:35 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-05-14 17:19:32 -0400 (Fri, 14 May 2004)
New Revision: 488

Added:
   trunk/pr/tutorial/tut5.pr
Modified:
   trunk/docs/tutorial/index.htm
   trunk/docs/tutorial/tutorial5.htm
Log:
added for statement and tut5

Modified: trunk/docs/tutorial/index.htm
===================================================================
--- trunk/docs/tutorial/index.htm	2004-05-14 18:37:58 UTC (rev 487)
+++ trunk/docs/tutorial/index.htm	2004-05-14 21:19:32 UTC (rev 488)
@@ -130,8 +130,18 @@
                   <li><a href="tutorial5.htm#ques">Question Functions_&amp; ?</a> 
                   <li><a href="tutorial5.htm#bool">obj.bool_?</a> 
                   <li><a href="tutorial5.htm#smplcode">Sample Code</a> 
+                  </ul>
+              <li><a href="tutorial5.htm#forstmt">4.2 For Statement</a> 
+                <ul>
+                      
+                  <li><a href="tutorial5.htm#objnext">obj.next()</a>
+                  <li><a href="tutorial5.htm#iters">Iterators</a> 
+                  <li><a href="tutorial5.htm#itertype">Iterator Types</a> 
+                  <li><a href="tutorial5.htm#forsmpl">Sample Code</a> 
                 </ul>
-            </ul>
+                </ul>
+              
+  
         </ul>
       </td>
     </tr>
Modified: trunk/docs/tutorial/tutorial5.htm
===================================================================
--- trunk/docs/tutorial/tutorial5.htm	2004-05-14 18:37:58 UTC (rev 487)
+++ trunk/docs/tutorial/tutorial5.htm	2004-05-14 21:19:32 UTC (rev 488)
@@ -103,6 +103,70 @@
 XXX 
 Many things are true 
 </pre>
+        <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="forstmt"></a>4.2 
+          For Statement</font></p>
+        <p>The &quot;for&quot; statement allows you to repeat a block of code 
+          multiple times. It also allows you to assign one or more data variable 
+          values for each time the code runs. </p>
+        <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="objnext"></a></font>The 
+          &quot;for&quot; statement is very flexible. Unlike other languages it 
+          does not work with a fixed variable type like an integer that it counts 
+          through or a list of items. Like the if-elif-else statement is uses 
+          a special type of function call that allows any type object to specify 
+          what should be done in the &quot;for&quot; statement. This call is obj.next_(). 
+        </p>
+        <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="iters"></a></font>Any 
+          object type can define .next_() just like object types defined .bool_?() 
+          to define what was True and False for the the &quot;if&quot; statement. 
+          When an object type defines .next_() that type of object is called an 
+          &quot;iterator&quot; type. You can call the &quot;iterator object&quot; 
+          with .next_() and it will return a result object over and over for each 
+          call until it is done, at which time it signals that it is done with 
+          an exception (we will discuss exceptions later).</p>
+        <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="itertype"></a></font>Some 
+          examples of common iterator types are integer-iterators which return 
+          the numbers 0, 1, 2, ... up to the value of the integer-1, string iterators 
+          which return the characters in a string, and a list iterator which returns 
+          the elements in a list. The for list makes it easy to loop once for 
+          each value returned by the iterator, so you can loop n times as an integer 
+          counts up, loop once for each character in a string, or loop once for 
+          each item in a list, etc.</p>
+        <p><font face="Verdana, Arial, Helvetica, sans-serif" size="+2"><a name="forsmpl"></a></font>The 
+          for statement is of the form &quot;for vars in iter: block&quot; where 
+          vars are names to assign to the results of the .next_() call on each 
+          iteration of the loop and iter is the iterator object. (Actually the 
+          object that is used to call .next_() on is an iterator that is generated 
+          from iter, not iter itself, but I'm sure these details are starting 
+          to bore you). Block is the code that is executed repeatedly. Here is 
+          some sample code:</p>
+        <pre># Prothon source file tut5.pr
+
+for i in 3: 
+    print i
+
+for c in "abc":  # ending print with comma
+    print c,     # suppresses newline at end
+
+print
+
+list = [0, 'a', 3.7]
+for item in list: 
+    print item,
+
+print
+
+d = {1:2, 3:4, 5:6}
+for t in d.items():
+    print t[0],t[1]</pre>
+        <p>The results of running this file are: </p>
+        <pre>0 
+1 
+2 
+a b c 
+0 a 3.7 
+1 2 
+3 4 
+5 6 </pre>
       </td>
     </tr>
   </table>
Added: trunk/pr/tutorial/tut5.pr
===================================================================
--- trunk/pr/tutorial/tut5.pr	2004-05-14 18:37:58 UTC (rev 487)
+++ trunk/pr/tutorial/tut5.pr	2004-05-14 21:19:32 UTC (rev 488)
@@ -0,0 +1,20 @@
+
+# Prothon source file tut5.pr
+
+for i in 3: 
+    print i
+
+for c in "abc":  # ending print with comma
+    print c,     # suppresses newline at end
+
+print
+
+list = [0, 'a', 3.7]
+for item in list: 
+    print item,
+
+print
+
+d = {1:2, 3:4, 5:6}
+for t in d.items():
+    print t[0],t[1]
\ No newline at end of file