### Navigation

- index
- next |
- previous |
- NEURON 7.3 documentation »
- HOC Language »

# HOC Keywords

help

> invokes the help system

> Syntax:

>   `help`

>   `help word`

> Description:
>   `Help word` sends a word to the help system. The word is looked up in the `nrn/lib/helpdict` file and if found Netscape is sent the appropriate URL to display the help text. If the word is not found, the URL for the table of contents is sent. Netscape must be running for the help system to work.

return

> Syntax:

>   `return`

>   `return expr`

>   `return objref`

> Description:

>   The `return` command will immediately exit from a procedure without returning a value.

>   The `return expr` command will immediately exit from a function which must return a value. This command must also be the last executable statement of a function. It is possible for a function to contain more than one `return` command, for instance in a series of `if else` statements; however, not more than one of the `return` commands may return a value at any given time.

>   The `return objref` command must be used to return from an obfunc.

> Example:

> >     func max(){
> >         if ($1 > $2){
> >                 return $1
> >         } else {
> >                 return $2
> >         }
> >     }

> > returns the maximum of two arguments which are read into the function. Eg. `max(3,6)`, where $1 is the first argument (3) and $2 is the second argument (6). This use of `max` would return the value 6.

> Warning

> See restriction of the break statement.

break

> Syntax:
>   `break`
> Description:
>   Immediately exit from a loop. Control transfers to the next statement after the loop statement.

> Warning

> This statement, as well as "return", "continue", and "stop" cannot occur within the scope of a statement that modifies the section stack such as

> section { statement }

> or the stack will not be properly popped. Also it should not be placed on a line that contains object syntax but should be placed on a line by itself. eg.

>         x.p() break

> should be written

>         x.p()
>         break

> Example:

> >     while(1) {
> >         x = fscan()
> >         if (x < 0) {
> >                 break;
> >         }
> >         print sqrt(x)
> >     }

continue

> Syntax:
>   `continue`
> Description:
>   Inside a compound statement of a loop, transfers control to the next iteration of the loop statement.

> Example:

> >     for i=1,10{
> >         if(i==6){
> >                 continue
> >         }
> >         print i
> >     }

> > prints the numbers: 1,2,3,4,5,7,8,9,10. 6 is left out because when i==6, the control is passed beyond the print statement to the next iteration of the loop.

> > You can accomplish the same thing with the following syntax:

> >     for i=1,10{
> >         if(i<6 || i>6){
> >                 print i
> >         }
> >     }

> Warning

> See restriction of the break statement.

stop

> Syntax:
>   `stop`
> Description:
>   Return control to the command level of the interpreter. This is a useful safety device for stopping the current execution of your program. Eg. you may wish to stop the program and print out an error message that lets you know if you have entered unacceptable arguments.

> Warning

> See restriction of the break statement.

if

> Syntax:

>   `if (expr) stmt1`

>   `if (expr) stmt1 else stmt2`

> Description:
>   Conditional statement. When the expr evaluates to a nonzero number (true) stmt1 is executed. With the `else` form, if the expression evaluates to zero (false) stm2 is executed.

> Example:

> >     i = 0       //initialize i
> >     j = 0       //initialize j
> >     if(vec.x[i] <= 10 && i < vec.size()){       //if the value of the ith element in vec
> >                                         //is less than or equal to 10, and
> >                                         //if i is an index within vec
> >         vec1.x[j] = vec.x[i]            //set the jth element of vec1 equal to that
> >                                         //ith element of vec
> >         i = i+1                         //increment i by 1
> >         j = j+1                         //increment j by 1
> >     } else{                                     //otherwise (This must be on the same line as the closing brace of
> >                                         //the previous statement in order to indicate that the compound
> >                                         //statement has not ended.)
> >         i = i+1                         //simply go to the next element of vec
> >     }

> See also

> `float_epsilon`, ifsec

else

> See also

> if

while

> Syntax:
>   `while (expr) stmt`
> Description:
>   Iteration statement. Repeatedly execute the statement as long as the expr evaluates to true.

> Example:

> >     numelements = 20
> >     i = 0
> >     while (i < numelements){
> >         print(cos(vec.x[i]))
> >         print(sin(vec.x[i]))
> >         i += 1
> >     }

> > prints the cosines and the sines of the `vec` elements up to `numelements`, which in this case = 20.

> See also

> for, break, continue

for

> Syntax:

>   `for(stmt1; expr2; stmt3) stmt`

>   `for var=expr1, expr2 stmt`

>   `for (var) stmt`

>   `for (var, expr) stmt`

>   `for iterator (args) stmt`

> Description:

>   Iteration statement. The `for` statement is similar to `while` in that it iterates over a statement. However, the `for` statement is more compact and contains within its parentheses the command to advance to the next iteration. Statements 1 and 3 may be empty.

>   This command also has a short form which always increments the iterations by one.

>       for *var*=*expr1*, *expr2*  stmt

>   is equivalent to

>       for(*var*=*expr1*; *var* <= *expr2*; *var*=*var*+1) stmt

>   However, expr1 and expr2 are evaluated only once at the beginning of the `for`.

>   `for (var) stmt`

>   Loops over all segments of the currently accessed section. var begins at 0 and ends at 1. In between var is set to the center position of each segment. Ie. stmt is executed nseg+2 times.

>   `for (var, expr) stmt`

>   If the expression evaluates to a non-zero value, it is exactly equivalent to `for (var) stmt` If it evaluates to 0 (within `float_epsilon` ) then the iteration does not include the 0 or 1 points. Thus `for(x, 0) { print x }` is exactly equivalent to `for (x) if (x > 0 && x < 1) { print x }`

>   The iterator form of the for loop executes the statement with a looping construct defined by the user.

> Example:

> >     for(i=0; i<=9; i=i+1){
> >         print i*2
> >     }

> > is equivalent to

> >     for i=0, 9 {
> >         print i*2
> >     }

> >     create axon
> >     access axon
> >     {nseg = 5  L=1000  diam=50  insert hh }
> >     for (x) print x, L*x
> >     for (x) if (x > 0 && x < 1) { print x, gnabar_hh(x) }

> See also

> iterator, break, continue, while, forall, forsec

print

> Syntax:
>   `print expr, string, ...`
> Description:
>   Any number of expressions and/or strings may be printed. A newline is printed at the end.

> Example:

> >     x=2
> >     y=3
> >     print x, "hello", "good-bye", y, 7

> > prints

> >     x hello good-bye 3 7

> > and then moves to the next line.

delete

> Syntax:
>   `delete varname`
> Description:
>   Deletes the variable name from the global namespace. Allows the varname to be declared as another type. It is up to the user to make sure it is safe to execute this statement since the variable may be used in an existing function.

read

> Syntax:
>   `read(var)`
> Description:
>   var is assigned the number input by the user, or the next number in the standard input, or the file opened with ropen. `read(var)` returns 0 on end of file and 1 otherwise.

> Example:

> >     for i=1, 5 {
> >         read(x)
> >         print x*x
> >     }

> > will await input from the user or from a file, and will print the square of each value typed in by the user, or read from the file, for the first five values.

> See also

> `xred()`, `File.ropen()`, `fscan()`, `File()`, `getstr()`

debug

> A toggle for parser debugging purposes. Prints the stack machine commands resulting from parsing a statement. Not useful to the user.

double

> Syntax:

>   `double var1[expr]`

>   `double var2[expr1][expr2]`

>   `double varn[expr1][expr2]...[exprn]`

> Description:

>   Declares a one-dimensional, a two-dimensional or an n-dimensional array of doubles. This is reminiscent of the command which creates an array in C, however, HOC does not demand that you specify whether or not numbers are integers. All numbers in all arrays will be doubles.

>   The index for each dimension ranges from 0 to expr-1. Arrays may be redeclared at any time, including within procedures. Thus arrays may have different lengths in different objects.

>   The `Vector` class for the ivoc interpreter provides convenient and powerful methods for manipulating arrays.

> Example:

> >     double vec[40]

> > declares an array with 40 elements, whereas

> >     objref vec
> >     vec = new Vector(40)

> > creates a vector (which is an array by a different name) with 40 elements which you can manipulate using the commands of the Vector class.

em

> Syntax:
>   `em`
> Description:

>   microemacs editor

>   This is a reasonably complete editor with many commands. These commands are listed in emacs. A tutorial is also available at emacstut.

>   When called from the interpreter, the command `^C` immediately returns to the interpreter and the current buffer is interpreted. Other commands follow:

>   `^X^F`
>     reads a file into a new buffer.
>   `^X^B`
>     changes buffers.
>   `^X^W` filename
>     saves (writes) a file under a specific name.
>   `^X^S`
>     saves a file under the last specified name.

depvar

> Syntax:
>   `depvar`
> Description:
>   Declare a variable to be a dependent variable for the purpose of solving simultaneous equations.

> Example:

> >     depvar x, y, z
> >      proc equations() {
> >        eqn x:: x + 2*y + z =  6
> >        eqn y:: x - y + z   =  2
> >        eqn z:: 2*x + y -z  = -3
> >      }
> >     equations()
> >     solve()
> >     print x,y,z

> > prints the values of x, y and z.

> See also

> eqn, `eqinit()`, `solve()`, `Matrix()`

eqn

> Syntax:

>   `eqn var:: expr = expr`

>   `eqn var: expr =`

>   `eqn var: = expr`

> Description:
>   Introduce a simultaneous equation. The single colon forms add the expressions to the indicated sides. This is convenient for breaking long equations down into more manageable parts which can be added together.

> Example:

> >     eqinit()
> >     depvar x, y, z
> >      proc equations() {
> >        eqn x:: x + 2*y + z =  6
> >        eqn y:: x - y + z   =  2
> >        eqn z:: 2*x + y -z  = -3
> >        eqn z: = 5 + 4y
> >      }
> >     equations()
> >     solve()
> >     print x,y,z

> > makes the right hand side of the z equation "2 + 4y" and solves for the values x, y, and z.

local

> Syntax:
>   `local var`
> Description:
>   Declare a list of local variables within a procedure or function Must be the first statement on the same line as the function declaration.

> Example:

> >     func count() {local i, x
> >         x = 0
> >         for i=0,40 {
> >                 if (vec.x[i] == 7) {
> >                          x = x+1
> >                 }
> >         }
> >         return x
> >     }

> > returns the number of elements which have the value of 7 in the first 40 elements of `vec`. `i` and `x` are local variables, and their usage here will not affect variables of the same name in other functions and procedures of the same program.

localobj

> Syntax:
>   `localobj var`
> Description:
>   Declare a list, comma separated, of local objrefs within a proc, func, iterator, or obfunc. Must be after the local statement (if that exists) on the same line as the function declaration

> Example:

> >     func sum() { local i, j  localobj tobj // sum from $1 to $2
> >         i = $1  j = $2
> >         tobj = new Vector()
> >         tobj.indgen(i, j ,1)
> >         return tobj.sum
> >     }
> >     sum(5, 10) == 45

strdef

> Syntax:
>   `strdef stringname`
> Description:

>   Declare a comma separated list of string variables. String variables cannot be arrays.

>   Strings can be passed as arguments to functions.

> Example:

> >     strdef a, b, c
> >     a = "Hello, "
> >     b = "how are you?"
> >     c = "What is your name?"
> >     print a, b
> >     print c

> > will print to the screen:

> >     Hello, how are you?
> >     What is your name?

setpointer

> Syntax:
>   `setpointer pvar, var`
> Description:

>   Connects pointer variables in membrane mechanisms to the address of var. eg. If `$NEURONHOME/examples/nmodl/synpre.mod` is linked into NEURON, then:

>       soma1 syn1=new synp(.5)
>       setpointer syn1.vpre, axon2.v(1)

>   would enable the synapse in soma1 to observe the axon2 membrane potential.

insert

> Syntax:
>   `insert mechanism`
> Description:
>   Insert the density mechanism in the currently accessed section. Not used for point processes--they are inserted with a different syntax.

> See also

> hh, pas, fastpas, `psection()`, Point Processes and Artificial Cells

uninsert

> Syntax:
>   `uninsert mechanism`
> Description:
>   Delete the indicated mechanism from the currently accessed section. Not for point processes.

### Navigation

- index
- next |
- previous |
- NEURON 7.3 documentation »
- HOC Language »