# Repeating Structures For Loops. Repeating Structures Tasks we need to complete are often very repetitive. Once a task has been mastered, repeating it.

## Presentation on theme: "Repeating Structures For Loops. Repeating Structures Tasks we need to complete are often very repetitive. Once a task has been mastered, repeating it."— Presentation transcript:

Repeating Structures For Loops

Repeating Structures Tasks we need to complete are often very repetitive. Once a task has been mastered, repeating it may lean to boredom and errors might then occur. This is where computers come in handy Computers are great at repetitive tasks because they never get bored and will never make careless mistakes (only mistakes made by the programmer!)

The For Loop In Java, there are different ways you can repeat a task The first and hardest way is the copy and paste method The method we’ll look at today is the For Loop Structure This structure is good to use when you know or can retrieve how many times something should be repeated

General For Loop Structure for ( ; ; ) { commands you want to repeat you can have more than one command } indentsemicolons repeated commands enclosed in braces

Example of For Loop for (int x=1; x<=10; x++) { g.drawString (“Hello”,10,(x*10)); } Initialization: creates a counter variable and give is a starting value (does not have to be 1) Test Condition: defines a condition that the counter variable checks at the beginning of each loop to be true before doing the loop Increment: this increments the counter variable –x++ is the same as x=x+1 –You can increment OR decrement by any value you want

Download ppt "Repeating Structures For Loops. Repeating Structures Tasks we need to complete are often very repetitive. Once a task has been mastered, repeating it."

Similar presentations