What is an enhanced for loop, and how exactly is it different from just a normal for loop? Is it just that it's easier to read? And why do you need a for loop in the first place? Can't you just print the array without it?
Hey Ariel! A enhanced for loop is pretty useful when you want to iterate (or go through) an array. Instead of having to define i, tell it to be less than the length, and to add 1 every time, we can just use an enhanced for loop which is is much simpler. In order to print arrays, we must use a for loop to go through every single index in that array. If you try to just System.out.println(array), it will result in a random number that we don't want. Instead, we must go to the first index, print it, go to the second one, print it, .... An example of printing arrays is here: https://repl.it/@AKumar/ArrayPrintExample#Main.java.Hope that answers your question!
Hey Ariel! A enhanced for loop is pretty useful when you want to iterate (or go through) an array. Instead of having to define i, tell it to be less than the length, and to add 1 every time, we can just use an enhanced for loop which is is much simpler. In order to print arrays, we must use a for loop to go through every single index in that array. If you try to just System.out.println(array), it will result in a random number that we don't want. Instead, we must go to the first index, print it, go to the second one, print it, .... An example of printing arrays is here: https://repl.it/@AKumar/ArrayPrintExample#Main.java. Hope that answers your question!