SlideShare une entreprise Scribd logo
1  sur  14
FOR Statement Presentation:
Group Members:
Muhammad

Saleem Nagri 10-EE-38
Mazhar Ali balti
10-EE-49
Ehtisham ul Haq Chilasi
10-EE-48
Khalid Amin Qazi
10-EE-160
Asad Ali Jaffari
10-EE-164
Mirpur university of Science and technology
AJ&K ,Pakistan
The For Statement
For

statement is repetition statement that is particularly well
suited for executing the body of a loop a specific number of
times that can be determined before the loop is
executed.
The header of a for loop contains three parts separated by
semicolons.
Before the loop begins, the first part of the header, called the
initialization, is executed.
The second part of the header is the boolean condition,
which is evaluated before the loop body (like the while loop). If
true, the body of the loop is executed, followed by the
execution of the third part of the header, which is called
increment.
Logic of a for loop
initialization
condition
evaluated
true
statement
increment

false
The for Statement
A

for statement has the following syntax:

The initialization
is executed once
before the loop begins

The statement is
executed until the
condition becomes false

for ( initialization ; condition ; increment ){
statement;
}
The increment portion is
executed at the end of each
iteration
The for Statement
for Loops
• Example:
for (int i = 1; i <= n; i++)
{
double interest = balance * rate /
100;
balance = balance + interest;
}
• Use a for loop when a variable runs from a starting
value to an ending value with a constant increment or
decrement
for Loop Flowchart
Execution of a

for Loop
for Loop Examples
import cs1.Keyboard;
public class Multiples
{
public static void main (String[] args)
{
final int PER_LINE = 5;
int value, limit, mult, count = 0;
System.out.print ("Enter a positive value: ");
value = Keyboard.readInt();
System.out.print ("Enter an upper limit: ");
limit = Keyboard.readInt();
System.out.println ();
System.out.println ("The multiples of " + value + " between " +
value + " and " + limit + " (inclusive) are:");
for (mult = value; mult <= limit; mult += value)
{
System.out.print (mult + "t");
count++;
if (count % PER_LINE == 0)
System.out.println();
for (mult = value; mult <= limit; mult += value)
{

System.out.print (mult + "t");
count++;
if (count % PER_LINE == 0)
System.out.println(); }

}

}

OUTPUT:
Enter a positive value: 7
Enter an upper limit: 400
The multiples of 7 between 7 and 400 (inclusive) are:
7

14

21

28

35

42

49

56

63

70

77

84

91

98

105

112

119

126

133

140

147

154

161

168

175

182

189

196

203

210

217

224

231

238

245

252

259

266

273

280

287

294

301

308

315

322

329

336

343

350

357

364

371

378

385

392

399
Nested Loop Examples
Nested Loop Examples
THE END……..
THANK YOU……

Contenu connexe

Tendances

Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in pythonRaginiJain21
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)jahanullah
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loopsbsdeol28
 
Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
The Ring programming language version 1.5.2 book - Part 46 of 181
The Ring programming language version 1.5.2 book - Part 46 of 181The Ring programming language version 1.5.2 book - Part 46 of 181
The Ring programming language version 1.5.2 book - Part 46 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 8 of 189
The Ring programming language version 1.6 book - Part 8 of 189The Ring programming language version 1.6 book - Part 8 of 189
The Ring programming language version 1.6 book - Part 8 of 189Mahmoud Samir Fayed
 

Tendances (15)

Python Loop
Python LoopPython Loop
Python Loop
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Java Programming: Loops
Java Programming: LoopsJava Programming: Loops
Java Programming: Loops
 
Nested loops
Nested loopsNested loops
Nested loops
 
C# Loops
C# LoopsC# Loops
C# Loops
 
C#
C#C#
C#
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Iteration
IterationIteration
Iteration
 
The Ring programming language version 1.5.2 book - Part 46 of 181
The Ring programming language version 1.5.2 book - Part 46 of 181The Ring programming language version 1.5.2 book - Part 46 of 181
The Ring programming language version 1.5.2 book - Part 46 of 181
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 
The Ring programming language version 1.6 book - Part 8 of 189
The Ring programming language version 1.6 book - Part 8 of 189The Ring programming language version 1.6 book - Part 8 of 189
The Ring programming language version 1.6 book - Part 8 of 189
 

Similaire à Java presentation

Repetition Structure
Repetition StructureRepetition Structure
Repetition StructurePRN USM
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopPriyom Majumder
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops Hemantha Kulathilake
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingPathomchon Sriwilairit
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6Vince Vo
 

Similaire à Java presentation (20)

130707833146508191
130707833146508191130707833146508191
130707833146508191
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
M C6java6
M C6java6M C6java6
M C6java6
 
Programming loop
Programming loopProgramming loop
Programming loop
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
For Loop
For LoopFor Loop
For Loop
 
07 flow control
07   flow control07   flow control
07 flow control
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
Loops in c
Loops in cLoops in c
Loops in c
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
DSA 103 Object Oriented Programming :: Week 3
DSA 103 Object Oriented Programming :: Week 3DSA 103 Object Oriented Programming :: Week 3
DSA 103 Object Oriented Programming :: Week 3
 
Loops
LoopsLoops
Loops
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Computer
ComputerComputer
Computer
 

Java presentation

  • 1. FOR Statement Presentation: Group Members: Muhammad Saleem Nagri 10-EE-38 Mazhar Ali balti 10-EE-49 Ehtisham ul Haq Chilasi 10-EE-48 Khalid Amin Qazi 10-EE-160 Asad Ali Jaffari 10-EE-164 Mirpur university of Science and technology AJ&K ,Pakistan
  • 2. The For Statement For statement is repetition statement that is particularly well suited for executing the body of a loop a specific number of times that can be determined before the loop is executed. The header of a for loop contains three parts separated by semicolons. Before the loop begins, the first part of the header, called the initialization, is executed. The second part of the header is the boolean condition, which is evaluated before the loop body (like the while loop). If true, the body of the loop is executed, followed by the execution of the third part of the header, which is called increment.
  • 3. Logic of a for loop initialization condition evaluated true statement increment false
  • 4. The for Statement A for statement has the following syntax: The initialization is executed once before the loop begins The statement is executed until the condition becomes false for ( initialization ; condition ; increment ){ statement; } The increment portion is executed at the end of each iteration
  • 6. for Loops • Example: for (int i = 1; i <= n; i++) { double interest = balance * rate / 100; balance = balance + interest; } • Use a for loop when a variable runs from a starting value to an ending value with a constant increment or decrement
  • 10. import cs1.Keyboard; public class Multiples { public static void main (String[] args) { final int PER_LINE = 5; int value, limit, mult, count = 0; System.out.print ("Enter a positive value: "); value = Keyboard.readInt(); System.out.print ("Enter an upper limit: "); limit = Keyboard.readInt(); System.out.println (); System.out.println ("The multiples of " + value + " between " + value + " and " + limit + " (inclusive) are:"); for (mult = value; mult <= limit; mult += value) { System.out.print (mult + "t"); count++; if (count % PER_LINE == 0) System.out.println();
  • 11. for (mult = value; mult <= limit; mult += value) { System.out.print (mult + "t"); count++; if (count % PER_LINE == 0) System.out.println(); } } } OUTPUT: Enter a positive value: 7 Enter an upper limit: 400 The multiples of 7 between 7 and 400 (inclusive) are: 7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 231 238 245 252 259 266 273 280 287 294 301 308 315 322 329 336 343 350 357 364 371 378 385 392 399