Strange loooking for loops to the left is the minimum

This preview shows page 5 out of 5 pages.

Strange loooking for loops To the left is the minimum requirement for a for loop. 1 2 3 4 5 6 7 8 9 boolean keepGoing = true; for ( ; keepGoing == true ; ) { System.out.print("Enter 'y' or 'n': "); keepGoing = ( … == 'y'); } for ( ; ; ) { } double val = 1.0; double test = 10.0; for ( ; val < test ; val = val + Math.random() * 2) { System.out.println(val); } //… Enter 'y' or 'n': y Enter 'y' or 'n': y Enter 'y' or 'n': n 1.0 2.4042126298906776 2.6688517153800486 … //random 9.741744156593892 30 What you need to know Syntax of while loops Syntax of for loops Designing loops: initialisation, condition, body, increment Loop condition: make sure that the loop condition will eventually evaluate to false.
Image of page 5
You've reached the end of this preview.

{[ 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