contents   index   previous   next



The with statement is used to save time when working with objects. It lets you assign a default object to a statement block, so you need not put the object name in front of its properties and methods. The object is automatically supplied by the interpreter. The following fragment illustrates using the Clib object.


with (Clib)


   printf("I am a camera");


   xxx = rand() % 5;




The Clib methods, Clib.printf(), Clib.srand(), Clib.rand(), and Clib.putchar(), in the sample above are called as if they had been written with Clib prefixed. All code in the block following a with statement seems to be treated as if the methods associated with the object named by the with statement were global functions. Global functions are still treated normally, that is, you do not need to prefix "global." to them unless you are distinguishing between two likenamed functions common to both objects.


If you were to jump, from within a with statement, to another part of a script, the with statement would no longer apply. In other words, the with statement only applies to the code within its own block, regardless of how the interpreter accesses or leaves the block.


You may not use goto and labels to jump into or out of the middle of a with statement block.