COS126_Lecture3-4_Conditionals_Loops_Arrays notes

COS126_Lecture3-4_Conditionals_Loops_Arrays notes - Lecture...

Info icon This preview shows pages 1–2. Sign up to view the full content.

Lecture 3 -... Audio recording started: 10:02 AM Tuesday, February 12, 2013 There are many uses of conditions and loops - they are quite useful Loop body is the stuff executed under the while function itself. If the statement in the declaration statement of while is true, the program must do everything in the loop body. Tabbing with DrJava gives the ideal indentation that it reads - it fixes the indentation Also use control + c or the reset button where necessary Don’t forget your braces with your while statements (provided they have more than one statement) Loops and conditionals can be used to find roots of functions as well. For statements initialize once then if the boolean statement is true, it will go ahead and do the statements below it. i++ means i = i + 1 For loops can be clearer and shorter than while loops. Sum += I is the same a sum = sum + I Nesting allows you to use for and while loops together. For instance an if statement in a while statement in a for statement It's best to utilize braces for nesting ifs and else statements together. You simply iterate over rows or columns. Nesting for loops is useful in arrays (2-dimensional data). Check the likelihood of winning a gambling game - probability (is it a fair game?)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '08
  • general computer science

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern