-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-control-syntax.vim
More file actions
51 lines (45 loc) · 918 Bytes
/
test-control-syntax.vim
File metadata and controls
51 lines (45 loc) · 918 Bytes
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
function! Fizz(num)
if a:num % 3 == 0
return 'Fizz'
else
return a:num
endif
endfunction
function! FizzBuzz(num)
if a:num % 15 == 0
return 'FizzBuzz'
elseif a:num % 5 == 0
return 'Buzz'
elseif a:num % 3 == 0
return 'Fizz'
else
return a:num
endif
endfunction
function! While()
let i = 1
while i <= 15
echo FizzBuzz(i)
let i += 1
endwhile
endfunction
function! For()
for i in range(1, 15)
echo FizzBuzz(i)
endfor
endfunction
function! Assert1to10(num)
if a:num < 1 || a:num > 10
throw 'Out of range: ' . a:num
endif
endfunction
function! Guess()
try
call Assert1to10(input('Guess a number: '))
echo "\n You are right!"
catch /^Out of range: .*/
echo "\nSomething bad..."
finally
echo 'Thank you for playing'
endtry
endfunction