• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

Working with an enhanced for loop?

November 12, 2012 by Rick Hernandez Leave a Comment

an enhanced for loop CAN NOT change the values of a standard for loop can do, so the new and enhanced for loop is great for working with arrays that need to be read in or access for maybe lets say a list, and don’t forget to pass an array to a whole method.

for(VARIABLE : ARRAY)
   {
      work that gets done ++
   }

for (int i: array)
   {
      sum += i;
   }

Hey hold on how am i going to pass an whole array to a method? good question, the syntax looks a little bit funky but over all not that bad.

methodname(int[] arrayName)
   {
      work that gets done...
   }

when declaring more then one variable it is important where the brackets are going to be placed for example:

array [] a,b,c;
array a,b,c [];

Try as much as possible NOT to do this, it will help avoid errors down the road.

Rick Hernandez

I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: Java, Programming

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in