[go: up one dir, main page]

0% found this document useful (0 votes)
36 views6 pages

JAVA For Loop

The document explains the Java For Loop, which is a control flow statement used for executing a block of code a fixed number of times. It consists of three parts: initialization, condition, and update or iteration. Examples are provided to illustrate the syntax and usage of the For Loop, along with an activity to create a multiplication table based on user input.

Uploaded by

chescamheyreyes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

JAVA For Loop

The document explains the Java For Loop, which is a control flow statement used for executing a block of code a fixed number of times. It consists of three parts: initialization, condition, and update or iteration. Examples are provided to illustrate the syntax and usage of the For Loop, along with an activity to create a multiplication table based on user input.

Uploaded by

chescamheyreyes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

JAVA For Loop

For Loop
is a control flow statement used to execute a block of
code repeatedly for a fixed number of iterations. It
consists of three parts.

1. Initialization – runs once before the loop starts. It


is usually used to declare and initialize a loop
control variable.
2. Condition – Loop continues as long as this
condition is evaluated to true. The loop stops when
the condition evaluated false.
3. Update or Iteration – this statement executes to
update the loop control variable.
For Loop Syntax
for (int i = 1; i <= 5; i++) {
System.out.println(“Output " + i);
}

Int i = 1; - is the initialization phase.


i >= 5; - is the condition phase.
i++ - is the iteration
Example
for (int i = 1; i <= 5; i++) {
System.out.println("Number: " + i);
}
OUTPUT:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
Example

for (int i = 10; i >= 1; i--) {


System.out.print(‘’ ’’+i);
}
OUTPUT:
10 9 8 7 6 5 4 3 2 1
Activity
Create a program for Multiplication table. Allow the user input a number
from 1-10 and make a multiplication table.
Please refer to the output below.

You might also like