BASIC · lesson 12 of 30 · Decisions and loopsA loop in a loop
The inner loop runs from start to end in each turn of the outer one. str$ with %4.0f lines up the columns.
12-nested-loops.yab Download 12-nested-loops.yab
rem A loop inside a loop: the multiplication table
for row = 1 to 6
for col = 1 to 6
print str$(row * col, "%4.0f");
next col
print
next row
Terminal
$ yabasic 12-nested-loops.yab
1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
6 12 18 24 30 36Exercise
Print a triangle of stars with five rows.