# Demonstration of loops

[XML] [Smart Pascal] [JavaScript] [Python] [output]

If you play the Countdown game you should find it useful to learn the 75 times table. This simple program makes use of a for loop to print it out.

We used the Blockly Playground to generate JavaScript and Python code from the same blocks.

See the following page for a while loop and a version of a repeat loop.

The blocks

## XML Code of Blocks

```<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="controls_for" id="ra6g4iVX%jh0U6!oOMp_" x="38" y="39">
<field name="VAR">i</field>
<value name="FROM">
<field name="NUM">1</field>
</value>
<value name="TO">
<field name="NUM">13</field>
</value>
<value name="BY">
<field name="NUM">1</field>
</value>
<statement name="DO">
<block type="text_print" id="A+ve0fTS6UC/V1-o,[^2">
<value name="TEXT">
<field name="TEXT">abc</field>
<block type="text_join" id="C7\$k6yzWM`WxW5`%5?3^">
<mutation items="3"></mutation>
<block type="variables_get" id="ZJlM(DH`iesuY7R\$aO-v">
<field name="VAR">i</field>
</block>
</value>
<block type="text" id=")OrrZ2pTJSL0N^b,[)hP">
<field name="TEXT"> times 75 is </field>
</block>
</value>
<block type="math_arithmetic" id="Y~5Vw4G.oG(FT,}u1pYX">
<field name="OP">MULTIPLY</field>
<value name="A">
<field name="NUM">1</field>
<block type="variables_get" id="N_s-`Dfuh|N\$tc-JB]Ua">
<field name="VAR">i</field>
</block>
</value>
<value name="B">
<field name="NUM">75</field>
</value>
</block>
</value>
</block>
</value>
</block>
</statement>
</block>
</xml>

```

## Generated Smart Pascal Code

```function Str(v: Variant) : string;
begin
asm
if (@v === 0) {
@Result = '0';
}
else if (@v === '') {
@Result = '';
}
else if (isNaN(@v)) {
@Result = @v;
}
else {
@Result = (@v).toString();
}
end;
end;

for var i := 1 to 13 do
begin
Console.writeln(StrJoin([Str(i), Str(' times 75 is '), Str(i * 75)],''));
end;

```

## Generated JavaScript

```var i;

for (i = 1; i <= 13; i++) {
window.alert([i,' times 75 is ',i * 75].join(''));
}

```

## Generated Python Code

```i = None

for i in range(1, 14):
print(''.join([str(x) for x in [i, ' times 75 is ', i * 75]]))

```

## Copy of Output

```1 times 75 is 75
2 times 75 is 150
3 times 75 is 225
4 times 75 is 300
5 times 75 is 375
6 times 75 is 450
7 times 75 is 525
8 times 75 is 600
9 times 75 is 675
10 times 75 is 750
11 times 75 is 825
12 times 75 is 900
13 times 75 is 975```
Programming - a skill for life!

XML, images and generated Smart Pascal code of examples including loops, arrays, validation and recursion