repeat is a reserved word in the programming language Lua.

In the BNF syntax of Lua, it appears as a terminal atom in one substitution rule:
statrepeat block until exp1
"stat" appears as a nonterminal atom in one substitution rule:
chunk → {stat [';']}

repeat is one of the three control structures of Lua (the other two being while and if). The condition expression (also called the guard) of a control structure may return any value. All values different from nil are considered true; only nil is considered false.

The body of the loop (block) is executed. From there, the behaviour of the repeat structure is identical to that of the while structure. The condition expression is evaluated, and every time it passes (evaluates to true) the body is executed and the condition expression is evaluated again. Once it fails (evaluates to false), the loop is over.

The flow of control of a repeat loop can be broken by the break statement, as with the while loop. If, in executing the block, Lua runs into a break statement, the rest of the body is skipped, the condition expression is not evaluated, and the program resumes immediately after the end of the control structure. Of course, a break only exits from one loop - a in a loop which is itself nested within a loop, will only exit from the innermost loop. while and for also count as loops, so for example a break in a while in a repeat will break out of the while loop only.

Quite often, a programmer may wish to break out of a loop which is not the innermost loop. Some programming languages provide a feature for naming a loop (or even just a section of code), and add the ability to associate a name with a break - so, in the previous example, if the outer loop was named 'RepeatLoop', then a break RepeatLoop will break out of both loops.

repeat can be implemented in terms of while, as follows:
repeat
  block
until exp1
becomes
FirstIteration = true
while (exp1 or FirstIteration)
  block
  FirstIteration = false
end
or, even more simply,
block
while exp1
  block
end
while can be expressed in terms of repeat, too, but that requires an extra control structure (an if). Thus, while is considered to be more fundamental a structure than repeat.

The superloop of a program sometimes looks like:
repeat
  block
until (true)
The program usually exits by use of the break statement, or through some operating system-provided means, usually an exception (e.g. in BASIC programs, the Escape key used to always exit the program - it was impossible, within early BASICs, to trap the Escape key), or by means of an instruction like exit (which is like a named break, where the name is associated with the entire program rather than any particular part of it).

Re*peat" (-p?t"), v. t. [imp. & p. p. Repeated; p. pr. & vb. n. Repeating.] [F. r'ep'eter, L. repetere; pref. re- re- + petere to fall upon, attack. See Petition.]

1.

To go over again; to attempt, do, make, or utter again; to iterate; to recite; as, to repeat an effort, an order, or a poem.

"I will repeat our former communication."

Robynson (More's Utopia).

Not well conceived of God; who, though his power Creation could repeat, yet would be loth Us to abolish. Milton.

2.

To make trial of again; to undergo or encounter again.

[Obs.]

Waller.

3. ScotsLaw

To repay or refund (an excess received).

To repeat one's self, to do or say what one has already done or said. -- To repeat signals, to make the same signals again; specifically, to communicate, by repeating them, the signals shown at headquarters.

Syn. -- To reiterate; iterate; renew; recite; relate; rehearse; recapitulate. See Reiterate.

 

© Webster 1913.


Re*peat" (r?-p?t"), n.

1.

The act of repeating; repetition.

2.

That which is repeated; as, the repeat of a pattern; that is, the repetition of the engraved figure on a roller by which an impression is produced (as in calico printing, etc.).

3. Mus.

A mark, or series of dots, placed before and after, or often only at the end of, a passage to be repeated in performance.

 

© Webster 1913.

Log in or register to write something here or to contact authors.