Visual Home Home

While.. For and All the Habits

Repetitive and Mindless tasks are the favorite for the processors. When you look at the laptop, it seems to know everything you want and gives it you. The fact is, we humans love habits. Habits are kind of loops that we are comfortable. Lets see the Habit forming Loops...

Repeat Loop

When a condition is true the code block in that condition needs to execute repeatedly, then use While loop.The pattern is to have "Exit condition" for the loop. Another way to get the same thing done is for... loop. Circles is created with For loop while the Rectangles where done using while loop.

Draw loop and Animation

We saw the draw loop produces the shapes on the canvas like a Flip Book, which is also a kind of loop. That is created by the program or the interpreter that executes our code. You can see the colors changing above randomly (frameRate is reduced to 5) and it is creating an illusion of animation, movement. That one visual has multiple concepts acting on it.

Using Multiple For loops

In efficient way of controlling the activity in a program is by using loops where it is unnecessary. Like the visual on the left, where the circles are drawn twice. I have given a slight opacity to show what has happened. Now we are starting to play, aren't we???

With that brief play with loops lets enter into the world of Functions