/
Loops (en)
Loops (en)
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-loop
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 animated icons on the screen using a loop. Make use of the sin() function to create a simple oscillation.
, multiple selections available,
Related content
Programming
Programming
More like this
Conditionals (en)
Conditionals (en)
More like this
Programming Basics 2020
Programming Basics 2020
More like this
Programming in Processing (java)
Programming in Processing (java)
More like this
Arduino Basics (en)
Arduino Basics (en)
More like this
p5.js Tiling and Repetition
p5.js Tiling and Repetition
More like this