while 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:
statwhile exp1 do block end
"stat" appears as a nonterminal atom in one substitution rule:
chunk → {stat [';']}

while is one of the three control structures of Lua (the other two being repeat 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 condition expression (exp1) is evaluated. If the expression fails (evaluates to false), the control structure is finished; the program continues at the next statement after the end of the structure (i.e. after the end). If the expression passes (evaluates to true), the body of the loop (block) is executed, then the condition expression is evaluated again; the body is executed and the condition is evaluated, again and again, until the expression fails, and then the loop is over.

The flow of control described above can be broken by one thing: the break statement. 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 break in a loop which is itself nested within a loop, will only exit from the innermost loop. repeat and for also count as loops, so for example a break in a repeat in a while will break out of the repeat 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 'WhileLoop', then a break WhileLoop will break out of both loops.

The superloop of a program often looks like:
while (true) do
  block
end
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).

While (?), n. [AS. hwil; akin to OS. hwil, hwila, OFries. hwile, D. wigl, G. weile, OHG. wila, hwila, hwil, Icel. hvila a bed, hvild rest, Sw. hvila, Dan. hvile, Goth. hweila a time, and probably to L. quietus quiet, and perhaps to Gr. the proper time of season. Cf. Quiet, Whilom.]

1.

Space of time, or continued duration, esp. when short; a time; as, one while we thought him innocent.

"All this while."

Shak.

This mighty queen may no while endure. Chaucer.

[Some guest that] hath outside his welcome while, And tells the jest without the smile. Coleridge.

I will go forth and breathe the air a while. Longfellow.

2.

That which requires time; labor; pains.

[Obs.]

Satan . . . cast him how he might quite her while. Chaucer.

At whiles, at times; at intervals.

And so on us at whiles it falls, to claim Powers that we dread. J. H. Newman.

-- The while, The whiles, in or during the time that; meantime; while. Tennyson. -- Within a while, in a short time; soon. -- Worth while, worth the time which it requires; worth the time and pains; hence, worth the expense; as, it is not always worth while for a man to prosecute for small debts.

 

© Webster 1913.


While, v. t. [imp. & p. p. Whiled (?); p. pr. & vb. n. Whiling.]

To cause to pass away pleasantly or without irksomeness or disgust; to spend or pass; -- usually followed by away.

The lovely lady whiled the hours away. Longfellow.

 

© Webster 1913.


While, v. i.

To loiter.

[R.]

Spectator.

 

© Webster 1913.


While, conj.

1.

During the time that; as long as; whilst; at the same time that; as, while I write, you sleep.

"While I have time and space."

Chaucer.

Use your memory; you will sensibly experience a gradual improvement, while you take care not to overload it. I. Watts.

2.

Hence, under which circumstances; in which case; though; whereas.

While as, While that, during or at the time that. [Obs.]

 

© Webster 1913.


While, prep.

Until; till.

[Obs. or Prov. Eng. & Scot.]

I may be conveyed into your chamber; I'll lie under your bed while midnight. Beau. & Fl.

 

© Webster 1913.

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