Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Statement Lists [5/6]

Why doesn't this code make a pause on each iteration?

Answer

A semicolon (;) symbol ends a statement list. In this case, there is a semicolon at the end of the println statement. Therefore, the sleepMs statement is not part of the statement list, thus it is outside the for loop.

The code is badly indented. It looks like the sleepMs statement is a part of the loop, but it isn't.

How would you make the sleepMs statement be a part of the statement list?

Solution

for #i=1..20
	: println i*i  << NOT ended by semicolon
	: sleepMs(200);

Loading...