Variables are declared by specifying their definition. Literal numeric arrays may be introduced by placing spaces between the numbers. Literal character arrays may be introduced by placing multiple characters between single quotes

However, note that in the context of classes and objects, global scope really means class scope or object scope. The general term for "a class or object" in J is "locale" (note the slight spelling difference from "local"). Most methods are implemented as J verbs, which have their arguments made available in implicitly defined array named y. (the period is a part of the name). This can be unpacked into a sequence of local variables by using a character array literal naming those variables as the left argument of =.

Because J is an array oriented language, most J programmers use data selection to implement conditional logic. While this is not a traditional feature of most languages, SQL programmers quite often use similar techniques.

However, J also offers more traditional if. statements within the body of defined verbs.

if. 1 = x then. y=: y + 3 end.

These conditional words are not themselves part of the statement syntax, and so may be spread across multiple lines.

Because J is an array oriented language, every operation is capable of looping over an arbitrarily dimensioned arrays. Thus, looping can happen implicitly within any expression.

x + y

will loop over all appropriate values, as long as the definitions of x and y conform.

2 3 4 + 10 100 1000

12 103 1004

This mechanism may be configured by specifying the rank of an operation, and the double quote character is used in this role (the double quote character does not delimit a string in J, and in general double quotes are used singly, not in pairs).

However, within the body of defined verbs, more traditional control words are available much in the fashion of conditional statements

while.
x < 100
do.
x=: x+1
blah, blah, blah
end.

In most cases you should use J's implicit looping. The exception is when not all data is knowable at one time, for example while servicing IO. However, even there, it might be wise to use J's event handling rather than an explicit loop.

For many purposes, no explicit output statements are needed. J is usually used in a calculator mode where results are displayed implicitly.

However, file output is also possible, using the notation 1!:2 (This may be thought of as library 1, entry point 2). Typically, this will be assigned a mnemonic name:

fwrite=: 1!:2

J uses its own numbering system output descriptors, and standard output is descriptor 2. (Likwise, file read is 1!:1 and standard input is descriptor 1.)

In the general context of file io, newlines must be specified explicitly, but with standard output always includes an implicit newline at the end. Under unix, write to /dev/tty to avoid implicit newlines.

All J nouns (data) are arrays with some number of dimensions (at least 0). The left caret is used to encapsulate one of these arrays. This operation is called boxing, which reflects the way these results are displayed.