Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Confluence
For you

Programming
Results will update as you type.
  • Tiling and Repetition
  • Reactors
  • Programming Basics: Parametric and Generative Graphic Design 2016
  • Archive
  • High Scores
  • Artificial Neural Network
  • Alternatives to the Processing IDE
  • p5.js Programming
  • Programming in Processing (java)
    • Starting with Processing (en)
    • Variables (en)
    • Classes and Objects (en)
    • Events und Functions (en)
    • Writing our own Functions (en)
    • Random Numbers (en)
    • Conditionals (en)
    • Loops (en)
      • Schleife (de)
    • Nested Loops (en)
    • Coordinates (en)
    • Arrays and Lists (en)
    • SVG + Images (en)
    • Motion and Temporality
    • Gesture Interactions
    • Using bitmaps as modifiers
    • Vectors
    • Animation
    • Animation 2
    • Simple Collision Detection
    • Sound
    • Typography

/
Loops (en)

Loops (en)

Nov 05, 2019

Analytics

Loading data...

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-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
Programming
More like this
Conditionals (en)
Conditionals (en)
Programming
More like this
Programming Basics 2020
Programming Basics 2020
Creative Coding
More like this
Programming in Processing (java)
Programming in Processing (java)
Programming
More like this
Arduino Basics (en)
Arduino Basics (en)
Electrical Engineering
More like this
p5.js Tiling and Repetition
p5.js Tiling and Repetition
Programming
More like this
{"serverDuration": 46, "requestCorrelationId": "40ba52bec1ab4f66baceb74b26f93ade"}