Skip to content

For loop exercises#

Question

What is the problem with the following loops:

A problematic loop
for (i=0; i>10; i++){
    print(i);
}
Another problematic loop
for (i=0; i<10; i--){
    print(i);
}

⚠ If you run them, you might have to kill your Fiji session.

Question

Can you write a for loop that runs 20 times?

Question

How could we count from 0 to 100, but in increments of 5?

Question

Can we can count backward (e.g. from 10 to 0) using a for loop?

Question

Can you write a loop within a loop? What do you need to pay attention to?