1 / 9

CS 240 – Computer Programming I Lab

CS 240 – Computer Programming I Lab. Kalpa Gunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/. Contact. Contact by e-mail kalpa@knoesis.org Office hours 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm. Intention.

mandek
Download Presentation

CS 240 – Computer Programming I Lab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 240 – Computer Programming ILab KalpaGunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/

  2. Contact • Contact by e-mail • 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 (<boolean condition>) { // loop body } Until the boolean condition is false Loop will iterate. First checks the condition and execute The body. <boolean condition> false true <loop body>

  5. do – while loop • do { // loop body } while (<boolean condition>) • Loops body is executed at least before checking the condition. <loop body> <boolean condition> true false

  6. for loop • Steps, initial action (only once) -> check condition -> body -> final action -> loop <initial action> <boolean condition> false true <loop body> <action>

  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, <power>); • 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.

More Related