Introduction to Computer Science I Do While Loop, For Loop Janyl - - PowerPoint PPT Presentation

introduction to computer science i
SMART_READER_LITE
LIVE PREVIEW

Introduction to Computer Science I Do While Loop, For Loop Janyl - - PowerPoint PPT Presentation

Introduction to Computer Science I Do While Loop, For Loop Janyl Jumadinova 9 April, 2018 Review: Repetition structures while() loop while (condition) { action(s) } 2/7 Review: Repetition structures while() loop while (condition) {


slide-1
SLIDE 1

Introduction to Computer Science I

Do While Loop, For Loop

Janyl Jumadinova 9 April, 2018

slide-2
SLIDE 2

Review: Repetition structures

while() loop

◮ while (condition) { action(s) } 2/7

slide-3
SLIDE 3

Review: Repetition structures

while() loop

◮ while (condition) { action(s) } 3/7

slide-4
SLIDE 4

Review: Repetition structures

while() loop

◮ while (condition) { action(s) }

  • Example:

int a = 10; while(a < 10) { System.out.print(a+" "); a++; }

3/7

slide-5
SLIDE 5

Review: Repetition structures

while() loop

◮ while (condition) { action(s) }

  • Example:

int a = 10; while(a < 10) { System.out.print(a+" "); a++; }

◮ Output: 3/7

slide-6
SLIDE 6

Repetition structures

do{ } while() loop

◮ do {action(s) } while(condition); 4/7

slide-7
SLIDE 7

Repetition structures

do{ } while() loop

◮ do {action(s) } while(condition); 5/7

slide-8
SLIDE 8

Repetition structures

do{ } while() loop

◮ do {action(s) } while(condition);

  • Example:

int a = 10; do { System.out.print(a+" "); a++; } while(a < 10);

5/7

slide-9
SLIDE 9

Repetition structures

do{ } while() loop

◮ do {action(s) } while(condition);

  • Example:

int a = 10; do { System.out.print(a+" "); a++; } while(a < 10);

◮ Output: 10 5/7

slide-10
SLIDE 10

For repetition structure

for ( init; testForFinal; modification ) { actionStatement(s);}

◮ The init section should create and initialize your loop control

variable.

◮ The testForFinal section should be a Boolean expression to

test for the final value.

◮ The modification section should be an arithmetic statement

(usually a ++ or – action) to modify the loop control variable.

6/7

slide-11
SLIDE 11

For loop

public class ForLoop { public static void main ( String args[] ) { for ( int counter = 1; counter <= 10; counter++) System.out.println ( counter ); } }

7/7