Download presentation
Presentation is loading. Please wait.
Published byCori Hines Modified over 9 years ago
1
CS 240 – Computer Programming I Lab Kalpa Gunaratna – kalpa@knoesis.orgkalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/
2
Contact Contact by e-mail kalpa@knoesis.org kalpa@knoesis.org Office hours 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm
3
Intention Familiar yourself with various loops available in Java language. Some loops have advantages above others but all loops can be used most of the time for many tasks. Loops, for, while, do while Any loop can be nested in whatever you want and for your requirement.
4
while loop while ( ) { // loop body } Until the boolean condition is false Loop will iterate. First checks the condition and execute The body. true false
5
do – while loop do { // loop body } while ( ) Loops body is executed at least before checking the condition. truefalse
6
for loop Steps, initial action (only once) -> check condition -> body -> final action -> loop true false
7
Following two for loops and while loop are equivalent. for( ; ; ){ // do something } for( ; true; ) { // do something } while( true ){ // do something }
8
In lab Remember the last week’s lab about printing a triangle. Numbers you have to print is all about powers of 2. Math.pow(2, ); Numbers should be exactly as they are shown in the assignment and also they should align in the exact way !
9
Post lab Repeat the same process as you did in in lab and use whole and do – while loops. No for loops ! You should use at least one of while and do – while loops.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.