Advertisement
Guest User

foreach v for....

a guest
Apr 26th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. object persons = {......};
  2. foreach (person in persons) {
  3. print="person";
  4. }
  5.  
  6. array persons = [....];
  7. foreach (person in persons) {
  8. print="person";
  9. }
  10.  
  11. # If you need to get the specific index for whatever reason though....
  12.  
  13. indexWhereFound = null;
  14. for (int i = 0; i < person.length; i++) {
  15. # Lets say you want to keep track of where exactly a certain person was found...that you can't exactly do on a foreach.
  16. if (person[i].isMexican === true) {
  17. indexWhereFound = i;
  18. return;
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement