Your SlideShare is downloading. ×
0
FOR Statement Presentation:
Group Members:
Muhammad

Saleem Nagri 10-EE-38
Mazhar Ali balti
10-EE-49
Ehtisham ul Haq Ch...
The For Statement
For

statement is repetition statement that is particularly well
suited for executing the body of a loo...
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 for Statement
for Loops
• Example:
for (int i = 1; i <= n; i++)
{
double interest = balance * rate /
100;
balance = balance + interest;
...
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,...
for (mult = value; mult <= limit; mult += value)
{

System.out.print (mult + "t");
count++;
if (count % PER_LINE == 0)
Sys...
Nested Loop Examples
Nested Loop Examples
THE END……..
THANK YOU……
Upcoming SlideShare
Loading in...5
×

Java presentation

97

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
97
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Java presentation"

  1. 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. 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. 3. Logic of a for loop initialization condition evaluated true statement increment false
  4. 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
  5. 5. The for Statement
  6. 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
  7. 7. for Loop Flowchart
  8. 8. Execution of a for Loop
  9. 9. for Loop Examples
  10. 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. 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
  12. 12. Nested Loop Examples
  13. 13. Nested Loop Examples
  14. 14. THE END…….. THANK YOU……
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×