blockly
2013年4月12日 星期五
費氏數列
<xml>
<block type="variables_set" inline="false" x="-385" y="-208">
<title name="VAR">fn</title>
<value name="VALUE">
<block type="text_prompt">
<title name="TYPE">NUMBER</title>
<title name="TEXT">請輸入數字</title>
</block>
</value>
<next>
<block type="variables_set" inline="false">
<title name="VAR">x</title>
<value name="VALUE">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
<next>
<block type="variables_set" inline="false">
<title name="VAR">y</title>
<value name="VALUE">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
<next>
<block type="variables_set" inline="false">
<title name="VAR">z</title>
<value name="VALUE">
<block type="math_number">
<title name="NUM">0</title>
</block>
</value>
<next>
<block type="controls_if" inline="false">
<mutation else="1"></mutation>
<value name="IF0">
<block type="logic_compare" inline="true">
<title name="OP">LTE</title>
<value name="A">
<block type="variables_get">
<title name="VAR">fn</title>
</block>
</value>
<value name="B">
<block type="math_number">
<title name="NUM">2</title>
</block>
</value>
</block>
</value>
<statement name="DO0">
<block type="variables_set" inline="false">
<title name="VAR">z</title>
<value name="VALUE">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
</block>
</statement>
<statement name="ELSE">
<block type="controls_for" inline="true">
<title name="VAR">i</title>
<value name="FROM">
<block type="math_number">
<title name="NUM">3</title>
</block>
</value>
<value name="TO">
<block type="variables_get">
<title name="VAR">fn</title>
</block>
</value>
<statement name="DO">
<block type="variables_set" inline="false">
<title name="VAR">z</title>
<value name="VALUE">
<block type="math_arithmetic" inline="true">
<title name="OP">ADD</title>
<value name="A">
<block type="variables_get">
<title name="VAR">x</title>
</block>
</value>
<value name="B">
<block type="variables_get">
<title name="VAR">y</title>
</block>
</value>
</block>
</value>
<next>
<block type="variables_set" inline="false">
<title name="VAR">x</title>
<value name="VALUE">
<block type="variables_get">
<title name="VAR">y</title>
</block>
</value>
<next>
<block type="variables_set" inline="false">
<title name="VAR">y</title>
<value name="VALUE">
<block type="variables_get">
<title name="VAR">z</title>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</statement>
</block>
</statement>
<next>
<block type="text_print" inline="false">
<value name="TEXT">
<block type="variables_get">
<title name="VAR">z</title>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</xml>
n階
xml檔
<xml>
<block type="variables_set" inline="false" x="-696" y="-353">
<title name="VAR">x</title>
<value name="VALUE">
<block type="text_prompt">
<title name="TYPE">NUMBER</title>
<title name="TEXT">請輸入n</title>
</block>
</value>
<next>
<block type="variables_set" inline="false">
<title name="VAR">y</title>
<value name="VALUE">
<block type="math_number">
<title name="NUM">0</title>
</block>
</value>
<next>
<block type="controls_for" inline="true">
<title name="VAR">i</title>
<value name="FROM">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
<value name="TO">
<block type="variables_get">
<title name="VAR">x</title>
</block>
</value>
<statement name="DO">
<block type="variables_set" inline="false">
<title name="VAR">y</title>
<value name="VALUE">
<block type="math_arithmetic" inline="true">
<title name="OP">ADD</title>
<value name="A">
<block type="variables_get">
<title name="VAR">y</title>
</block>
</value>
<value name="B">
<block type="variables_get">
<title name="VAR">i</title>
</block>
</value>
</block>
</value>
</block>
</statement>
<next>
<block type="text_print" inline="false">
<value name="TEXT">
<block type="variables_get">
<title name="VAR">y</title>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
<block type="math_number" x="-804" y="-174">
<title name="NUM">1</title>
</block>
<block type="math_number" x="-806" y="-137">
<title name="NUM">1</title>
</block>
</xml>
<xml>
<block type="variables_set" inline="false" x="-696" y="-353">
<title name="VAR">x</title>
<value name="VALUE">
<block type="text_prompt">
<title name="TYPE">NUMBER</title>
<title name="TEXT">請輸入n</title>
</block>
</value>
<next>
<block type="variables_set" inline="false">
<title name="VAR">y</title>
<value name="VALUE">
<block type="math_number">
<title name="NUM">0</title>
</block>
</value>
<next>
<block type="controls_for" inline="true">
<title name="VAR">i</title>
<value name="FROM">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
<value name="TO">
<block type="variables_get">
<title name="VAR">x</title>
</block>
</value>
<statement name="DO">
<block type="variables_set" inline="false">
<title name="VAR">y</title>
<value name="VALUE">
<block type="math_arithmetic" inline="true">
<title name="OP">ADD</title>
<value name="A">
<block type="variables_get">
<title name="VAR">y</title>
</block>
</value>
<value name="B">
<block type="variables_get">
<title name="VAR">i</title>
</block>
</value>
</block>
</value>
</block>
</statement>
<next>
<block type="text_print" inline="false">
<value name="TEXT">
<block type="variables_get">
<title name="VAR">y</title>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
<block type="math_number" x="-804" y="-174">
<title name="NUM">1</title>
</block>
<block type="math_number" x="-806" y="-137">
<title name="NUM">1</title>
</block>
</xml>
訂閱:
意見 (Atom)











