Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

deutsche Version

A loop is a control statement that allows us to repeat a code block . Loops contain a conditional which determines how many times the code block is repeated.

There are few different loop types:


For-loop

for([variable declaration],[condition],[step]) {
}

for(int i=0; i <= 100; i++)
{
   println(i);
}

While-loopRemove

while([condition]) {
}

int x=0;
while(x <= 100)
{
   println(x);
   x++;
}

Do-While-loop

do{
} while([condition]);

This is the same as the while loop, but we check the condition at the end of the code block. The do-while-loop will always execute at least once, no matter the condition. 

int x=0;
do
{
   println(x);
   x++;
}while(x <= 100);

Exercise 6

Write a program that creates a line of trees on the screen using a loop.