Merging Sorted Arrays

[XML] [Smart Pascal] [JavaScript] [Python] [PHP] [Output]

This example is a Blockly implementation of the merge algorithm. In addition to the generated code from BlocklyToSmartPascal we show the JavaScript, Python and PHP code obtained from the same blocks in the Blockly Playground.

The blocks

The blocks

XML Code of Blocks

<xml xmlns="http://www.w3.org/1999/xhtml">
  <block type="variables_set" id="ww]Q4,U6u2kqlUwk4MVf" x="-413" y="-438">
    <field name="VAR">strA</field>
    <value name="VALUE">
      <block type="text" id="4|^cCIau#4lpI1zti`_p">
        <field name="TEXT">and,but,dip,ore,rot,the,ton,tor</field>
      </block>
    </value>
    <next>
      <block type="variables_set" id="!9]/sfq6fZLM$XAa,JUR">
        <field name="VAR">strB</field>
        <value name="VALUE">
          <block type="text" id="(Eb:~QiN1ng|OvM1Z0=E">
            <field name="TEXT">dim,its,mud,off,one,sit,too,two</field>
          </block>
        </value>
        <next>
          <block type="variables_set" id="H;uCVjdm,/$3VM,QPqA_">
            <field name="VAR">strArrayA</field>
            <value name="VALUE">
              <block type="lists_split" id="933;CK)]|n[fkJx$6qy%">
                <mutation mode="SPLIT"></mutation>
                <field name="MODE">SPLIT</field>
                <value name="INPUT">
                  <block type="variables_get" id="}eLo76^?5~^#9JG(7]D(">
                    <field name="VAR">strA</field>
                  </block>
                </value>
                <value name="DELIM">
                  <shadow type="text" id="t`ZU2Sw?NzR~`z3ew?h7">
                    <field name="TEXT">,</field>
                  </shadow>
                </value>
              </block>
            </value>
            <next>
              <block type="variables_set" id="~~QJ@x%l!){#3p@osb5h">
                <field name="VAR">strArrayB</field>
                <value name="VALUE">
                  <block type="lists_split" id="~30RCL3!L=s#T7ru^_z}">
                    <mutation mode="SPLIT"></mutation>
                    <field name="MODE">SPLIT</field>
                    <value name="INPUT">
                      <block type="variables_get" id="Y9PI7GM-#j8(FM}_g,%n">
                        <field name="VAR">strB</field>
                      </block>
                    </value>
                    <value name="DELIM">
                      <shadow type="text" id="p?1B{c*fzax~^ao!Ie,K">
                        <field name="TEXT">,</field>
                      </shadow>
                    </value>
                  </block>
                </value>
                <next>
                  <block type="variables_set" id="5IR{ho4M(d-t:ba/SlWm">
                    <field name="VAR">intLengthC</field>
                    <value name="VALUE">
                      <block type="math_arithmetic" id="oJ9:m6Kif1)avBYPCLtM">
                        <field name="OP">ADD</field>
                        <value name="A">
                          <shadow type="math_number" id="ke4Gn0g1^EL+3#)1E:tc">
                            <field name="NUM">1</field>
                          </shadow>
                          <block type="lists_length" id="@69*gD2w_?Kz^_kAj-An">
                            <value name="VALUE">
                              <block type="variables_get" id="kP-)2wPyiLmx]q7)r6k,">
                                <field name="VAR">strArrayA</field>
                              </block>
                            </value>
                          </block>
                        </value>
                        <value name="B">
                          <shadow type="math_number" id="ZiQ:qOe0*!2x)BG(CkDB">
                            <field name="NUM">1</field>
                          </shadow>
                          <block type="lists_length" id="v@!YQ|otFq7)sb3V]qYa">
                            <value name="VALUE">
                              <block type="variables_get" id="?NJ-e5I=LbUlHOe9Qv*a">
                                <field name="VAR">strArrayB</field>
                              </block>
                            </value>
                          </block>
                        </value>
                      </block>
                    </value>
                    <next>
                      <block type="variables_set" id="b~(.yj,2W3f7YI#vM(=J">
                        <field name="VAR">strArrayC</field>
                        <value name="VALUE">
                          <block type="lists_repeat" id="m~Gi_Nl.lptKMt!Hw|f,">
                            <value name="ITEM">
                              <block type="text" id="x$f8bF.adp3=}h19bHzz">
                                <field name="TEXT"></field>
                              </block>
                            </value>
                            <value name="NUM">
                              <shadow type="math_number" id="6X=*At17q~^ne)XJJl9V">
                                <field name="NUM">5</field>
                              </shadow>
                              <block type="variables_get" id="IDOpYTmEB0$jtKq`T~Jo">
                                <field name="VAR">intLengthC</field>
                              </block>
                            </value>
                          </block>
                        </value>
                        <next>
                          <block type="variables_set" id="9pBw?Q`br|d16-*.5Kj|">
                            <field name="VAR">intIndexA</field>
                            <value name="VALUE">
                              <block type="math_number" id="#^HF)ZK-2G{v[3-iKFW?">
                                <field name="NUM">1</field>
                              </block>
                            </value>
                            <next>
                              <block type="variables_set" id="s?.ZvR(zdO1o$|S!!ysK">
                                <field name="VAR">intIndexB</field>
                                <value name="VALUE">
                                  <block type="math_number" id="8--t/w0EUJH7VpvR*X*M">
                                    <field name="NUM">1</field>
                                  </block>
                                </value>
                                <next>
                                  <block type="variables_set" id="{QSBDlzH3[g^PR[fhshU">
                                    <field name="VAR">intIndexC</field>
                                    <value name="VALUE">
                                      <block type="math_number" id="MI(H`jq,_mrvYWIjx0.;">
                                        <field name="NUM">1</field>
                                      </block>
                                    </value>
                                    <next>
                                      <block type="controls_whileUntil" id="b^Es(avWUuHMVoq)t|+Z">
                                        <field name="MODE">WHILE</field>
                                        <value name="BOOL">
                                          <block type="logic_operation" id="vdP]caCMWzlcF(ZEKes]">
                                            <field name="OP">AND</field>
                                            <value name="A">
                                              <block type="logic_compare" id="DY0XCBXR@tE8`nEm*6bV">
                                                <field name="OP">LTE</field>
                                                <value name="A">
                                                  <block type="variables_get" id="v`:4`V%%$IZQWf$av-!]">
                                                    <field name="VAR">intIndexA</field>
                                                  </block>
                                                </value>
                                                <value name="B">
                                                  <block type="lists_length" id="zoUfI}Lj$mKOgO%EMp)B">
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="!QHYMN1GQ][g8t^:aV4u">
                                                        <field name="VAR">strArrayA</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                              </block>
                                            </value>
                                            <value name="B">
                                              <block type="logic_compare" id="Ba6Sp)dE:RXTct}fO.y0">
                                                <field name="OP">LTE</field>
                                                <value name="A">
                                                  <block type="variables_get" id="i/-LNnbM)`jz:qY+50,I">
                                                    <field name="VAR">intIndexB</field>
                                                  </block>
                                                </value>
                                                <value name="B">
                                                  <block type="lists_length" id="g-_?B$`CMYTIN|uvV~q,">
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="x*}~.~pce%;vj}3y/)lS">
                                                        <field name="VAR">strArrayB</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                              </block>
                                            </value>
                                          </block>
                                        </value>
                                        <statement name="DO">
                                          <block type="controls_if" id="c/*]x,|@8*Pk%b._IMkc">
                                            <mutation else="1"></mutation>
                                            <value name="IF0">
                                              <block type="logic_compare" id="~tp1cXHH#gC3l}Wrpg]+">
                                                <field name="OP">LT</field>
                                                <value name="A">
                                                  <block type="lists_getIndex" id="Wz;=s_lDPlj[Jif_hJw%">
                                                    <mutation statement="false" at="true"></mutation>
                                                    <field name="MODE">GET</field>
                                                    <field name="WHERE">FROM_START</field>
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="Q3FT?8?dj8ZM=)SN@~dT">
                                                        <field name="VAR">strArrayA</field>
                                                      </block>
                                                    </value>
                                                    <value name="AT">
                                                      <block type="variables_get" id="1fP6iY%PrV(9.6raT.uW">
                                                        <field name="VAR">intIndexA</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                                <value name="B">
                                                  <block type="lists_getIndex" id="7tU^?EmyM_SPN}0tB9%e">
                                                    <mutation statement="false" at="true"></mutation>
                                                    <field name="MODE">GET</field>
                                                    <field name="WHERE">FROM_START</field>
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="|K=H2g1ug-]XrtSX|ZWu">
                                                        <field name="VAR">strArrayB</field>
                                                      </block>
                                                    </value>
                                                    <value name="AT">
                                                      <block type="variables_get" id="5UnLDoVX|+,5P[mt7C/r">
                                                        <field name="VAR">intIndexB</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                              </block>
                                            </value>
                                            <statement name="DO0">
                                              <block type="lists_setIndex" id="Th}qJ2s4EZ2jjAzS;G$o">
                                                <mutation at="true"></mutation>
                                                <field name="MODE">SET</field>
                                                <field name="WHERE">FROM_START</field>
                                                <value name="LIST">
                                                  <block type="variables_get" id="bKQ5TD0_W!)r[Y_#B913">
                                                    <field name="VAR">strArrayC</field>
                                                  </block>
                                                </value>
                                                <value name="AT">
                                                  <block type="variables_get" id="c5n[U$x=e;Q/5iO,y4Mg">
                                                    <field name="VAR">intIndexC</field>
                                                  </block>
                                                </value>
                                                <value name="TO">
                                                  <block type="lists_getIndex" id="8u8+bmd!HPmL@DqKwxY,">
                                                    <mutation statement="false" at="true"></mutation>
                                                    <field name="MODE">GET</field>
                                                    <field name="WHERE">FROM_START</field>
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="niI59[tX:/}|SXGbO^C}">
                                                        <field name="VAR">strArrayA</field>
                                                      </block>
                                                    </value>
                                                    <value name="AT">
                                                      <block type="variables_get" id="{,9QnFhPykP!fbZ8n1Ay">
                                                        <field name="VAR">intIndexA</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                                <next>
                                                  <block type="math_change" id="k:@Dra3%vL*ulr_o$:XO">
                                                    <field name="VAR">intIndexA</field>
                                                    <value name="DELTA">
                                                      <shadow type="math_number" id="^6t{aZl+JU%l21vmHrR4">
                                                        <field name="NUM">1</field>
                                                      </shadow>
                                                    </value>
                                                  </block>
                                                </next>
                                              </block>
                                            </statement>
                                            <statement name="ELSE">
                                              <block type="lists_setIndex" id="]JWJ*)K~hO`J#=u{;s3i">
                                                <mutation at="true"></mutation>
                                                <field name="MODE">SET</field>
                                                <field name="WHERE">FROM_START</field>
                                                <value name="LIST">
                                                  <block type="variables_get" id="3aPEx(f[8UF]rj%y;S`I">
                                                    <field name="VAR">strArrayC</field>
                                                  </block>
                                                </value>
                                                <value name="AT">
                                                  <block type="variables_get" id="cF!4Eq#X5v|tu1[yWlyS">
                                                    <field name="VAR">intIndexC</field>
                                                  </block>
                                                </value>
                                                <value name="TO">
                                                  <block type="lists_getIndex" id="K=Gty@[hHF`VoNam@J[H">
                                                    <mutation statement="false" at="true"></mutation>
                                                    <field name="MODE">GET</field>
                                                    <field name="WHERE">FROM_START</field>
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="nXfP.xSw0ARLsYZJG{?z">
                                                        <field name="VAR">strArrayB</field>
                                                      </block>
                                                    </value>
                                                    <value name="AT">
                                                      <block type="variables_get" id="QSkb?Y1q/v7[rz=rBxBB">
                                                        <field name="VAR">intIndexB</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                                <next>
                                                  <block type="math_change" id="C8%I4?0SWsmi^MyhA#X0">
                                                    <field name="VAR">intIndexB</field>
                                                    <value name="DELTA">
                                                      <shadow type="math_number" id="ql6Vd;jc_CUwNh23Fx~)">
                                                        <field name="NUM">1</field>
                                                      </shadow>
                                                    </value>
                                                  </block>
                                                </next>
                                              </block>
                                            </statement>
                                            <next>
                                              <block type="math_change" id=".p??}Vp|E5)D%)bQ.OE(">
                                                <field name="VAR">intIndexC</field>
                                                <value name="DELTA">
                                                  <shadow type="math_number" id="b2#;p7j.oH@.J0(.@3O2">
                                                    <field name="NUM">1</field>
                                                  </shadow>
                                                </value>
                                              </block>
                                            </next>
                                          </block>
                                        </statement>
                                        <next>
                                          <block type="controls_if" id="oL,$(kvDmm0de3Z~BE{o">
                                            <mutation else="1"></mutation>
                                            <value name="IF0">
                                              <block type="logic_compare" id="N)?B^Bj:M(1ct3uz:pia">
                                                <field name="OP">LTE</field>
                                                <value name="A">
                                                  <block type="variables_get" id=".GPjEJRzj,+_@1(nv.;N">
                                                    <field name="VAR">intIndexA</field>
                                                  </block>
                                                </value>
                                                <value name="B">
                                                  <block type="lists_length" id="4]Yh^vsd_2,VnyhAXcsQ">
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="Yh$Calg!_O?xuQnD3jKH">
                                                        <field name="VAR">strArrayA</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                              </block>
                                            </value>
                                            <statement name="DO0">
                                              <block type="controls_for" id="kO0DftKi8cP+MiO/8f+F">
                                                <field name="VAR">i</field>
                                                <value name="FROM">
                                                  <shadow type="math_number" id="H0qd)[Wz,+hQ#0`=:wk6">
                                                    <field name="NUM">1</field>
                                                  </shadow>
                                                  <block type="variables_get" id="4?s*h`*o{=r#%ymydY]y">
                                                    <field name="VAR">intIndexA</field>
                                                  </block>
                                                </value>
                                                <value name="TO">
                                                  <shadow type="math_number" id="i3C7E-Or8H3dT|h8[^Wj">
                                                    <field name="NUM">10</field>
                                                  </shadow>
                                                  <block type="lists_length" id="a__]iZ+u6gs8sS,a@H{-">
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="+w+ihJmW)^i[(%_AC540">
                                                        <field name="VAR">strArrayA</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                                <value name="BY">
                                                  <shadow type="math_number" id="YrA#;VmaV{Im%}a9;r#O">
                                                    <field name="NUM">1</field>
                                                  </shadow>
                                                </value>
                                                <statement name="DO">
                                                  <block type="lists_setIndex" id="^tctuJ!]#lEyN;A$Dix_">
                                                    <mutation at="true"></mutation>
                                                    <field name="MODE">SET</field>
                                                    <field name="WHERE">FROM_START</field>
                                                    <value name="LIST">
                                                      <block type="variables_get" id="Mt2?Iut3e`[}^}#$_2Ur">
                                                        <field name="VAR">strArrayC</field>
                                                      </block>
                                                    </value>
                                                    <value name="AT">
                                                      <block type="variables_get" id="Q[|{l$5C5Gff4WB{qWjL">
                                                        <field name="VAR">intIndexC</field>
                                                      </block>
                                                    </value>
                                                    <value name="TO">
                                                      <block type="lists_getIndex" id="!cCWwrvIJa$fP.M5sC?e">
                                                        <mutation statement="false" at="true"></mutation>
                                                        <field name="MODE">GET</field>
                                                        <field name="WHERE">FROM_START</field>
                                                        <value name="VALUE">
                                                          <block type="variables_get" id="@[}Mce@6aB`37-%PTgQ_">
                                                            <field name="VAR">strArrayA</field>
                                                          </block>
                                                        </value>
                                                        <value name="AT">
                                                          <block type="variables_get" id="Pz3Iu-KIUhxm4dwn~_B$">
                                                            <field name="VAR">i</field>
                                                          </block>
                                                        </value>
                                                      </block>
                                                    </value>
                                                    <next>
                                                      <block type="math_change" id="#HW}1OH85ziS-|yt2}iU">
                                                        <field name="VAR">intIndexC</field>
                                                        <value name="DELTA">
                                                          <shadow type="math_number" id="w_TKbPxgLhs/Wm8n|j]=">
                                                            <field name="NUM">1</field>
                                                          </shadow>
                                                        </value>
                                                      </block>
                                                    </next>
                                                  </block>
                                                </statement>
                                              </block>
                                            </statement>
                                            <statement name="ELSE">
                                              <block type="controls_for" id="7q~_n89E/^/OC0VN)E]L">
                                                <field name="VAR">i</field>
                                                <value name="FROM">
                                                  <shadow type="math_number" id="H0qd)[Wz,+hQ#0`=:wk6">
                                                    <field name="NUM">1</field>
                                                  </shadow>
                                                  <block type="variables_get" id=":3XT|C.ONtHZz0cL:/}#">
                                                    <field name="VAR">intIndexB</field>
                                                  </block>
                                                </value>
                                                <value name="TO">
                                                  <shadow type="math_number" id="i3C7E-Or8H3dT|h8[^Wj">
                                                    <field name="NUM">10</field>
                                                  </shadow>
                                                  <block type="lists_length" id="=:@.4?m4EVbG^~oJd`:+">
                                                    <value name="VALUE">
                                                      <block type="variables_get" id="QFIps?[mHCO8gU-,auF9">
                                                        <field name="VAR">strArrayB</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                                <value name="BY">
                                                  <shadow type="math_number" id="u5#KqOu+CYFn,rJQKY%@">
                                                    <field name="NUM">1</field>
                                                  </shadow>
                                                </value>
                                                <statement name="DO">
                                                  <block type="lists_setIndex" id=";$3sI5.qgJx|16:z7Py]">
                                                    <mutation at="true"></mutation>
                                                    <field name="MODE">SET</field>
                                                    <field name="WHERE">FROM_START</field>
                                                    <value name="LIST">
                                                      <block type="variables_get" id="NE83)skIjId^l]IWRl];">
                                                        <field name="VAR">strArrayC</field>
                                                      </block>
                                                    </value>
                                                    <value name="AT">
                                                      <block type="variables_get" id="KGUeS6EhS@Qv=s6j|[a$">
                                                        <field name="VAR">intIndexC</field>
                                                      </block>
                                                    </value>
                                                    <value name="TO">
                                                      <block type="lists_getIndex" id="k)R_M-TSsNCt7pRWen.$">
                                                        <mutation statement="false" at="true"></mutation>
                                                        <field name="MODE">GET</field>
                                                        <field name="WHERE">FROM_START</field>
                                                        <value name="VALUE">
                                                          <block type="variables_get" id="=AfEhAp/.T;5)z0fArm=">
                                                            <field name="VAR">strArrayB</field>
                                                          </block>
                                                        </value>
                                                        <value name="AT">
                                                          <block type="variables_get" id=".33I,V@R,ChI+D/]yaAD">
                                                            <field name="VAR">i</field>
                                                          </block>
                                                        </value>
                                                      </block>
                                                    </value>
                                                    <next>
                                                      <block type="math_change" id="w(7@[`]Q}Gx@7gNuq^O[">
                                                        <field name="VAR">intIndexC</field>
                                                        <value name="DELTA">
                                                          <shadow type="math_number" id="[F?6R9YrBi~zgrsTngGu">
                                                            <field name="NUM">1</field>
                                                          </shadow>
                                                        </value>
                                                      </block>
                                                    </next>
                                                  </block>
                                                </statement>
                                              </block>
                                            </statement>
                                            <next>
                                              <block type="text_print" id="YB/6*2RZ4u9:56NIjaxG">
                                                <value name="TEXT">
                                                  <shadow type="text" id="adg8TpL~gFkS*D)K6TFi">
                                                    <field name="TEXT">abc</field>
                                                  </shadow>
                                                  <block type="lists_split" id="an$S)}x2m)=;@##[=x?E">
                                                    <mutation mode="JOIN"></mutation>
                                                    <field name="MODE">JOIN</field>
                                                    <value name="INPUT">
                                                      <block type="variables_get" id="B4%qbR]dh:e=Fnz?cI,I">
                                                        <field name="VAR">strArrayC</field>
                                                      </block>
                                                    </value>
                                                    <value name="DELIM">
                                                      <shadow type="text" id="i63BYNMS]soKFiTsr4+|">
                                                        <field name="TEXT">,</field>
                                                      </shadow>
                                                    </value>
                                                  </block>
                                                </value>
                                              </block>
                                            </next>
                                          </block>
                                        </next>
                                      </block>
                                    </next>
                                  </block>
                                </next>
                              </block>
                            </next>
                          </block>
                        </next>
                      </block>
                    </next>
                  </block>
                </next>
              </block>
            </next>
          </block>
        </next>
      </block>
    </next>
  </block>
</xml>

Generated Smart Pascal Code

var intIndexA: Integer;
var intIndexB: Integer;
var intIndexC: Integer;
var intLengthC: Integer;
var strA: String;
var strArrayA: TStrArray;
var strArrayB: TStrArray;
var strArrayC: TStrArray;
var strB: String;


function RepeatArray(Value: Variant; n: integer): Variant;
begin
  var Arr := [];
  for var i := 0 to n - 1 do
    Arr[i] := Value;
  Result := Variant(Arr);
end;


strA := 'and,but,dip,ore,rot,the,ton,tor';
strB := 'dim,its,mud,off,one,sit,too,two';
strArrayA := StrSplit(strA, ',');
strArrayB := StrSplit(strB, ',');
intLengthC := strArrayA.length + strArrayB.length;
strArrayC := TStrArray(RepeatArray('', intLengthC));
intIndexA := 1;
intIndexB := 1;
intIndexC := 1;
while ((intIndexA <= strArrayA.length) and (intIndexB <= strArrayB.length)) do
begin
  if ((strArrayA[(intIndexA - 1)] < strArrayB[(intIndexB - 1)])) then
  begin
    strArrayC[(intIndexC - 1)] := strArrayA[(intIndexA - 1)];
    intIndexA += 1;
  end
  else
  begin
    strArrayC[(intIndexC - 1)] := strArrayB[(intIndexB - 1)];
    intIndexB += 1;
  end;
  intIndexC += 1;
end;
if ((intIndexA <= strArrayA.length)) then
begin
  for var i := intIndexA to strArrayA.length step 1 do
  begin
    strArrayC[(intIndexC - 1)] := strArrayA[(i - 1)];
    intIndexC += 1;
  end;
end
else
begin
  for var i := intIndexB to strArrayB.length step 1 do
  begin
    strArrayC[(intIndexC - 1)] := strArrayB[(i - 1)];
    intIndexC += 1;
  end;
end;
Console.writeln(StrJoin(strArrayC, ','));    

Generated JavaScript Code

var strArrayC, intIndexC, i, strArrayB, intIndexB, strArrayA, intIndexA, intLengthC, strB, strA;

function listsRepeat(value, n) {
  var array = [];
  for (var i = 0; i < n; i++) {
    array[i] = value;
  }
  return array;
}


strA = 'and,but,dip,ore,rot,the,ton,tor';
strB = 'dim,its,mud,off,one,sit,too,two';
strArrayA = strA.split(',');
strArrayB = strB.split(',');
intLengthC = strArrayA.length + strArrayB.length;
strArrayC = listsRepeat('', intLengthC);
intIndexA = 1;
intIndexB = 1;
intIndexC = 1;
while (intIndexA <= strArrayA.length && intIndexB <= strArrayB.length) {
  if (strArrayA[(intIndexA - 1)] < strArrayB[(intIndexB - 1)]) {
    strArrayC[(intIndexC - 1)] = strArrayA[(intIndexA - 1)];
    intIndexA = (typeof intIndexA == 'number' ? intIndexA : 0) + 1;
  } else {
    strArrayC[(intIndexC - 1)] = strArrayB[(intIndexB - 1)];
    intIndexB = (typeof intIndexB == 'number' ? intIndexB : 0) + 1;
  }
  intIndexC = (typeof intIndexC == 'number' ? intIndexC : 0) + 1;
}
if (intIndexA <= strArrayA.length) {
  var i_end = strArrayA.length;
  var i_inc = 1;
  if (intIndexA > i_end) {
    i_inc = -i_inc;
  }
  for (i = intIndexA; i_inc >= 0 ? i <= i_end : i >= i_end; i += i_inc) {
    strArrayC[(intIndexC - 1)] = strArrayA[(i - 1)];
    intIndexC = (typeof intIndexC == 'number' ? intIndexC : 0) + 1;
  }
} else {
  var i_end2 = strArrayB.length;
  var i_inc2 = 1;
  if (intIndexB > i_end2) {
    i_inc2 = -i_inc2;
  }
  for (i = intIndexB; i_inc2 >= 0 ? i <= i_end2 : i >= i_end2; i += i_inc2) {
    strArrayC[(intIndexC - 1)] = strArrayB[(i - 1)];
    intIndexC = (typeof intIndexC == 'number' ? intIndexC : 0) + 1;
  }
}
window.alert(strArrayC.join(','));

Generated Python Code

from numbers import Number

strArrayC = None
intIndexC = None
i = None
strArrayB = None
intIndexB = None
strArrayA = None
intIndexA = None
intLengthC = None
strB = None
strA = None

def upRange(start, stop, step):
  while start <= stop:
    yield start
    start += abs(step)

def downRange(start, stop, step):
  while start >= stop:
    yield start
    start -= abs(step)


strA = 'and,but,dip,ore,rot,the,ton,tor'
strB = 'dim,its,mud,off,one,sit,too,two'
strArrayA = strA.split(',')
strArrayB = strB.split(',')
intLengthC = len(strArrayA) + len(strArrayB)
strArrayC = [''] * intLengthC
intIndexA = 1
intIndexB = 1
intIndexC = 1
while intIndexA <= len(strArrayA) and intIndexB <= len(strArrayB):
  if strArrayA[int(intIndexA - 1)] < strArrayB[int(intIndexB - 1)]:
    strArrayC[int(intIndexC - 1)] = strArrayA[int(intIndexA - 1)]
    intIndexA = (intIndexA if isinstance(intIndexA, Number) else 0) + 1
  else:
    strArrayC[int(intIndexC - 1)] = strArrayB[int(intIndexB - 1)]
    intIndexB = (intIndexB if isinstance(intIndexB, Number) else 0) + 1
  intIndexC = (intIndexC if isinstance(intIndexC, Number) else 0) + 1
if intIndexA <= len(strArrayA):
  i_end = float(len(strArrayA))
  for i in (float(intIndexA) <= i_end) and upRange(float(intIndexA), i_end, 1) or downRange(float(intIndexA), i_end, 1):
    strArrayC[int(intIndexC - 1)] = strArrayA[int(i - 1)]
    intIndexC = (intIndexC if isinstance(intIndexC, Number) else 0) + 1
else:
  i_end2 = float(len(strArrayB))
  for i in (float(intIndexB) <= i_end2) and upRange(float(intIndexB), i_end2, 1) or downRange(float(intIndexB), i_end2, 1):
    strArrayC[int(intIndexC - 1)] = strArrayB[int(i - 1)]
    intIndexC = (intIndexC if isinstance(intIndexC, Number) else 0) + 1
print(','.join(strArrayC))
    

Generated PHP Code

$strArrayC;
$intIndexC;
$i;
$strArrayB;
$intIndexB;
$strArrayA;
$intIndexA;
$intLengthC;
$strB;
$strA;

function length($value) {
  if (is_string($value)) {
    return strlen($value);
  } else {
    return count($value);
  }
}

function lists_repeat($value, $count) {
  $array = array();
  for ($index = 0; $index < $count; $index++) {
    $array[] = $value;
  }
  return $array;
}


$strA = 'and,but,dip,ore,rot,the,ton,tor';
$strB = 'dim,its,mud,off,one,sit,too,two';
$strArrayA = explode(',', $strA);
$strArrayB = explode(',', $strB);
$intLengthC = length($strArrayA) + length($strArrayB);
$strArrayC = lists_repeat('', $intLengthC);
$intIndexA = 1;
$intIndexB = 1;
$intIndexC = 1;
while ($intIndexA <= length($strArrayA) && $intIndexB <= length($strArrayB)) {
  if ($strArrayA[($intIndexA - 1)] < $strArrayB[($intIndexB - 1)]) {
    $strArrayC[($intIndexC - 1)] = $strArrayA[($intIndexA - 1)];
    $intIndexA += 1;
  } else {
    $strArrayC[($intIndexC - 1)] = $strArrayB[($intIndexB - 1)];
    $intIndexB += 1;
  }
  $intIndexC += 1;
}
if ($intIndexA <= length($strArrayA)) {
  $_i_start = $intIndexA;
  $_i_end = length($strArrayA);
  $_i_inc = 1;
  if ($_i_start > $_i_end) {
    $_i_inc = -$_i_inc;
  }
  for ($i = $_i_start; $_i_inc >= 0 ? $i <= $_i_end : $i >= $_i_end; $i += $_i_inc) {
    $strArrayC[($intIndexC - 1)] = $strArrayA[($i - 1)];
    $intIndexC += 1;
  }
} else {
  $_i_start2 = $intIndexB;
  $_i_end2 = length($strArrayB);
  $_i_inc2 = 1;
  if ($_i_start2 > $_i_end2) {
    $_i_inc2 = -$_i_inc2;
  }
  for ($i = $_i_start2; $_i_inc2 >= 0 ? $i <= $_i_end2 : $i >= $_i_end2; $i += $_i_inc2) {
    $strArrayC[($intIndexC - 1)] = $strArrayB[($i - 1)];
    $intIndexC += 1;
  }
}
print(implode(',', $strArrayC));

Copy of Output

and,but,dim,dip,its,mud,off,one,ore,rot,sit,the,ton,too,tor,two
Programming - a skill for life!

Suggestions, with examples such as Caesar cipher and Fibonacci sequence, for Blockly programs that you could develop