Professional Documents
Culture Documents
While PDF
While PDF
While PDF
false
boolean_expression
true
statement
(body of loop)
false
boolean_expression
true
statement
(body of loop)
int i = 0; ! !int i = 1; !
while (i < n) { ! ! !while (i < n) {!
System.out.print(“*”);! ! !System.out.print
!i++;! (“*”);!
}! ! !i++;!
System.out.println();! !}!
!System.out.println();!
For n = 5 the output is
***** (5 asterisks) Output?
int i = 0; ! !int i = 0; !
while (i < n) { ! ! !while (i <= n) {!
System.out.print(“*”);! ! !System.out.print
!i++;! (“*”);!
}! ! !i++;!
System.out.println();! !}!
!System.out.println();!
For n = 5 the output is
***** (5 asterisks) Output?
int i = 0; !
Do you know which
while (i < n) {!
company has this address?
! !
System.out.print(“*”);! Apple Computer
!i--;!
1 Infinite Loop
}!
Cupertino, CA 95014
System.out.println();!
Examples:
n=5 sum = 15
n = 19 sum = 190
statement
true
boolean_expression
false
!int i = 0; // initialize!
!do {!
!! System.out.print(“*”); !
!! i++; // update!
!} while (i < n); // test!
!System.out.println();!
Use de Morgan’s law to prove the Boolean expressions are the same!