0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-21 21:49:51 +01:00
posthog/hogvm/__tests__/loops.hog

77 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

print('-- test while loop --')
{
let i := 0
while (i < 3) {
i := i + 1
print(i)
}
print(i)
}
print('-- test for loop --')
{
for (let i := 0; i < 3; i := i + 1) {
2024-08-27 17:04:54 +02:00
print(i) // prints 3 times
}
}
print('-- test emptier for loop --')
{
let i := 0;
for (;i < 3;) {
print('woo')
i := i + 1;
}
print('hoo')
}
2024-07-11 18:34:21 +02:00
print('-- for in loop with arrays --')
{
let arr := [1, 2, 3]
for (let i in arr) {
print(i)
}
}
print('-- for in loop with arrays and keys --')
{
let arr := [1, 2, 3]
for (let k, v in arr) {
print(k, v)
}
}
print('-- for in loop with tuples --')
{
let tup := (1, 2, 3)
for (let i in tup) {
print(i)
}
}
print('-- for in loop with tuples and keys --')
{
let tup := (1, 2, 3)
for (let k, v in tup) {
print(k, v)
}
}
print('-- for in loop with dicts --')
{
let obj := {'first': 'v1', 'second': 'v2', 'third': 'v3'}
for (let i in obj) {
print(i)
}
}
print('-- for in loop with dicts and keys --')
{
let obj := {'first': 'v1', 'second': 'v2', 'third': 'v3'}
for (let k, v in obj) {
print(k, v)
}
}