CS 1102 - AY2019-T4_ Discussion Assignment.pdf - CS 1102 AY2019-T4 Discussion Assignment HOME CONTACT US RESOURCES LINKS FACULTY MY COURSES MENU CS 1102

CS 1102 - AY2019-T4_ Discussion Assignment.pdf - CS 1102...

This preview shows page 1 - 4 out of 47 pages.

6/4/2019 CS 1102 - AY2019-T4: Discussion Assignment 1/47 Home My courses CS 1102 - AY2019-T4 18 April - 24 April Discussion Forum Unit 2 Discussion Assignment Subscribe HOME CONTACT US RESOURCES LINKS FACULTY MY COURSES MENU     Search forums Discussion Assignment by Eric Goh (Instructor) - Thursday, 11 April 2019, 5:09 PM Describe the for loop and compare with the for-each loop by describing the operation of each and discussing how they di±er from each other. You must include the role of enums in your description and provide an example of a for loop and a for-each loop. 46 words Permalink | Reply Re: Discussion Assignment by Dalton Overlin - Saturday, 20 April 2019, 1:53 AM Introduction For this assignment, I will ²rst start with explaining what a standard for loop is, and give an example of one. Then I will explain what a for-each loop is, and give an example of a for-each loop. After giving the two descriptions, and examples I will draw a
Image of page 1

Subscribe to view the full document.

6/4/2019 CS 1102 - AY2019-T4: Discussion Assignment 2/47 comparison between a standard for loop, and a for-each loop. Then after drawing a comparison I will discuss the roles of enums, or enumerations, and give some examples on how they are useful, and why they are called constants. The for Loop The standard for loop can be used for many things, but in this example below I will be using the for loop to iterate through and print each element of an array. In the example, the variable x is initialized as an array, the array is then assigned the value of ²ve elements, then each of those elements is assigned random four-digit numbers to represent years. The for loop then uses incrementation to iterate through each array element of x. It starts at position 0, then works its way through the array with the help of the count++; statement that increments the variable count each time the loop runs. Then once count is equal to the length of elements in the array the for loop will stop. This results in the printing of each of the elements contained within the array. This demonstrates that the for loop runs for every time that variable count is not equal to the length of elements within the array. So when the loop ends, and it goes to start again if the loop condition returns true, such as count not being equal to the length of the array it will run, but if it is false it will not run (Programiz.com, n.d.).
Image of page 2
6/4/2019 CS 1102 - AY2019-T4: Discussion Assignment 3/47 package forexample; public class ForExample { public static void main(String[] args) { // --------This example is the standard for loop! int[] x; // This initializes a new array. x = new int[5]; // This creates 5 new elements in the array, by default each new element of an array with a int base is 0 x[0] = 1909; // This along with the next few assignment statements assigns values to each of the elements of the array x.
Image of page 3

Subscribe to view the full document.

Image of page 4
  • Fall '18

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

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes