Patricjs - object orientated JavaScript



Nested Loops

This is an example program running in the Patric.js environment.

The code is as follows;

loop 20;
   circle 80,80;
      loop 5;
            triangle;
      next;
next;

The loop command tells the program to repeat the lines between the loop and the next command by the number of times indicated by the number or argument that follows the loop statement. The loop 5; statement tells the computer repeat the inside or nested loop 5 times befoure the next outside loop is run. The triangle; statement tells it to draw a triangle with a random size, as the size hasn't been specified and at a random position. Note there will be five triangles drawn for every circle drawn.The next next; statement tells it to repeat the inner loop. The last next; statement tells it to repeat the outer loop.The lines that are repeated are those between the loop and next commands.



Copyright © 2016 · All Rights Reserved · patric.co.uk