Cecil
19+ years progress programming and still learning.
I saw a YouTube video the other day and I thought it was quite interesting about hiring programmers and asking them the write a simple piece of code.
So today I thought I actually write the FizzBuzz game in the ABL and I came up with 3 alternatives which did the same thing.
What alternative code could you come up with in creating the FizzBuzz game?
1st
2nd:
3rd (I think this is my most elegant one I wrote):
So today I thought I actually write the FizzBuzz game in the ABL and I came up with 3 alternatives which did the same thing.
What alternative code could you come up with in creating the FizzBuzz game?
1st
Code:
define variable i as integer no-undo.
define variable result as character no-undo.
do i = 1 to 100:
if i MOD 3 ne 0 and i MOD 5 ne 0 then
do:
result = result + string(i) + '~r~n'.
next.
end.
if i MOD 3 eq 0 then
result = result + 'Fizz'.
if i MOD 5 eq 0 then
result = result + 'Buzz'.
result = result + '~r~n'.
end.
message result
view-as alert-box info.
2nd:
Code:
define variable i as integer no-undo.
define variable result as character no-undo.
do i = 1 to 100:
case true:
when (i MOD 3 eq 0 and i MOD 5 eq 0) then
result = result + 'FizzBuzz~r~n'.
when (i MOD 3 eq 0) then
result = result + 'Fizz~r~n'.
when (i MOD 5 eq 0) then
result = result + 'Buzz~r~n'.
otherwise
result = result + string(i) + '~r~n'.
end case.
end.
message result
view-as alert-box info.
3rd (I think this is my most elegant one I wrote):
Code:
define variable i as integer no-undo.
define variable result as character no-undo.
do i = 1 to 100:
assign
result = result + string(i) when (i MOD 3 ne 0 and i MOD 5 ne 0)
result = result + 'Fizz' when (i MOD 3 eq 0)
result = result + 'Buzz' when (i MOD 5 eq 0)
result = result + '~r~n'.
end.
message result
view-as alert-box info.
Last edited: