moved examples to examples folder

This commit is contained in:
2020-11-13 17:50:55 -06:00
parent 928b01f52c
commit 4ff1e59042
6 changed files with 1 additions and 8 deletions

13
examples/fortest.lua Normal file
View File

@@ -0,0 +1,13 @@
local function fact(num)
var total = 1
for (var i = num; i > 0; i = i - 1) do
total = total * i
end
return total
end
for (var x = 0; x < 1000; x=x+1) do
for (var z = 0; z < 100; z=z+1) do
print("The factorial of " .. z .. " is " .. fact(z))
end
end

29
examples/newtest.cosmo Normal file
View File

@@ -0,0 +1,29 @@
class test
function __init(self, x)
self.setArg(x)
end
function fact(self)
var total = 1
for (var i = self.x; i > 0; i = i - 1) do
total = total * i;
end
return total
end
function setArg(self, x)
self.x = x
end
end
var t = test(1)
for (var x = 1; x < 1000; x = x + 1) do
for (var i = 1; i < 100; i = i + 1) do
t.setArg(i)
print(t.fact())
end
end

26
examples/test.cosmo Normal file
View File

@@ -0,0 +1,26 @@
class test
function __init(self, str)
self.hello = str
end
function print(self, i)
var str = self.hello
for (var x = i; x > 0; x=x-1) do
str = str .. "!"
end
print(str)
end
end
var obj = test("Hello world")
for (var i = 1; i <= 1; i=i+1) do
obj.print(i)
end
test.debug = function(self)
print("hi from " .. self)
end
obj.debug()

21
examples/test.lua Normal file
View File

@@ -0,0 +1,21 @@
local function fact(i)
local total = 1
local x = i
while (x > 1) do
total = total * x
x = x - 1
end
return total
end
local i = 1
while i < 1000 do
local x = 1
while x < 100 do
print("The factorial of " .. x .. " is " .. fact(x))
x = x + 1
end
i = i + 1
end