The FizzBuzz Example in Magik Programming Language

  • 时间:2020-10-12 15:56:23
  • 分类:网络文摘
  • 阅读:202 次

The Magik programming language as described in here is a powerful dynamic-typed object-oriented programming language. Currently, it has been used widely at GE Smallworld GIS products. It has been ported to Java VM (Virtual Machine) at 2012.

The FizzBuzz is a good exercise to get familiar with any programming languages, and here we go:

# Write a short program that prints each number from 1 to 100 on a new line.
# For each multiple of 3, print “Fizz” instead of the number.
# For each multiple of 5, print “Buzz” instead of the number.
# For numbers which are multiples of both 3 and 5, print “FizzBuzz” instead of the number.

# I love Magik!
_package sw;
$

_block
    _for i _over range(1, 100)
    _loop
        _local div3? << i _mod 3 = 0
        _local div5? << i _mod 5 = 0
        _if div3? _andif div5? _then
            write("FizzBuzz")
        _elif div3? _then
            write("Fizz")
        _elif div5? _then
            write("Buzz")
        _else
            write(i)
        _endif
    _endloop
_endblock

Start a Magik session, then Compile in Visual Studio Code using Ctrl+F7 shortcut (the Magik-VS-code extension) and you should see the results printing out to the console correctly.

fizzbuzz-magik-exercise The FizzBuzz Example in Magik Programming Language fizzbuzz magik programming programming languages tutorial

fizzbuzz-magik-exercise

–EOF (The Ultimate Computing & Technology Blog) —

推荐阅读:
保健养生:秋季的健康饮食的营养原则  进口食品营养标签必须符合国家规定  如何读懂包装食品营养标签核心信息  食用油的选择:解密食用油养生之道  对牙齿的健康非常有益的几种食物  常吃这些食物可让你拥有健康的牙齿  转基因食品安全立法的不足和完善建议  食品添加剂过量对人体健康带来的危害  揭秘零食里面的食品添加剂及其危害  食品学专家解析转基因食品安全问题 
评论列表
添加评论