A common use of the NEW command is to protect %variables. Local variables starting with % are accessible within procedures such as methods even if they are created outside the scope of that procedure. If you want to use % variables within code without worrying about them being previously defined for some other purpose use a NEW command to preserve any existing value they may have. When you exit the stack level where the NEW command was used any previous value for the variable is restored.

Also note, the NEW command does not just preserve the simple unscripted values of values, it preserves the all subscripts of the variable as well.

 

Test     ;
         Set x="Before New"
         For i=1:1:10 set x(i)=i
         ZW x
         Write !
         New x
         Set x="After NEW"
         ZWrite x
 
 
d Test
x="Before New"
x(1)=1
x(2)=2
x(3)=3
x(4)=4
x(5)=5
x(6)=6
x(7)=7
x(8)=8
x(9)=9
x(10)=10
 
x="After NEW"