Forums Register Login

What does this code mean in java?

+Pie Number of slices to send: Send


the " : "

I actually tries to find java signs, but it did not come up for some reason. I know what =, ==, !=, || means, but not : lol

thanks guys
+Pie Number of slices to send: Send
Search for "enhanced for loop".
+Pie Number of slices to send: Send
1
+Pie Number of slices to send: Send
If I tell you that you read that as

For each int x in numbers

… does that help?

By the way: call your ints i j k rather than x y z.
1
+Pie Number of slices to send: Send
yes! perfect thank you!! Something so simple was never taught to me =)
+Pie Number of slices to send: Send
can you also tell me how enhanced for loops can help me make my code more efficient? and how are they better than traditional for loops?
+Pie Number of slices to send: Send
It's mostly syntax candy so you can write more succinct code. I doubt there is a significant difference in performance though, if any.
+Pie Number of slices to send: Send
 

MarirS NasavinirS wrote:can you also tell me how enhanced for loops can help me make my code more efficient? and how are they better than traditional for loops?


Hi,

You cannot state like that. They were created for purpose mainly to iterate through collections in a "nicer", "simpler" syntax. And you're allowed basically to iterate only one way, > forward >.
Traditional "for" loop actually is more flexible.
+Pie Number of slices to send: Send
Nicer, simpler, and more abstract. If "consistency is the hobgoblin of small minds", then Java was designed by giants. For iteration, we had array loops, while/next loops, and later Iterators.

The "for-each" construct replaces many of them and makes it easier to swap in and out different collection types without having to change the loop code.
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 664 times.
Similar Threads
Validate method not completing
just java 2 p. 119
using the java.lang.character class
multiples project (three five) project euler
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:23:56.