Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e569440391
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 81 lines (65 sloc) 1.265 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#! /usr/bin/lua
--
-- lua-TestMore : <http://fperrad.github.com/lua-TestMore/>
--
-- Copyright (C) 2009-2010, Perrad Francois
--
-- This code is licensed under the terms of the MIT/X11 license,
-- like Lua itself.
--

--[[

=head1 Lua while statement

=head2 Synopsis

% prove 011-while.t

=head2 Description

See "Lua 5.2 Reference Manual", section 3.3.4 "Control Structures",
L<http://www.lua.org/manual/5.2/manual.html#3.3.4>.

See "Programming in Lua", section 4.3 "Control Structures".

=cut

]]

print("1..11")

a = {}
local i = 1
while a[i] do
    i = i + 1
end
if i == 1 then
    print("ok 1 - while empty")
else
    print("not ok 1 - " .. i)
end

a = {"ok 2 - while ", "ok 3", "ok 4"}
local i = 1
while a[i] do
    print(a[i])
    i = i + 1
end

a = {"ok 5 - with break", "ok 6", "stop", "more"}
local i = 1
while a[i] do
    if a[i] == 'stop' then break end
    print(a[i])
    i = i + 1
end
if i == 3 then
    print("ok 7 - break")
else
    print("not ok 7 - " .. i)
end

x = 3
local i = 1
while i<=x do
    print("ok " .. 7+i)
    i = i + 1
end
if i == 4 then
    print("ok 11")
else
    print("not ok 11 - " .. i)
end

-- Local Variables:
-- mode: lua
-- lua-indent-level: 4
-- fill-column: 100
-- End:
-- vim: ft=lua expandtab shiftwidth=4:
Something went wrong with that request. Please try again.