Connecting Tech Pros Worldwide Forums | Help | Site Map

Why does this simple for loop create multiple errors?

Steel546's Avatar
Newbie
 
Join Date: Mar 2009
Posts: 17
#1: 2 Weeks Ago
Expand|Select|Wrap|Line Numbers
  1.    public static void main(String[] args) {
  2.  
  3.          double modArray[]= new double[10];
  4.  
  5.          for (int i =1, i < modArray.length(), i++){
  6.                 modArray[i]= (26*i+7)%31;
  7.                 } //end for
  8.         System.out.println(modArray);
  9.     }//end main
I really don't understand why this creates errors as a simple for loop? Errors such as "i is already defined in java.lang.string[]", "; expected", "> expected", and boolean required? Can anyone shed any light on this?

jx2 jx2 is offline
Familiar Sight
 
Join Date: Feb 2007
Location: Bristol UK
Posts: 227
#2: 2 Weeks Ago

re: Why does this simple for loop create multiple errors?


Your syntax is wrong
line 5 should look :
Expand|Select|Wrap|Line Numbers
  1.          for (int i =1; i < modArray.length; i++){
  2. //some code here
  3. }
  4.  
regards
Jan
Steel546's Avatar
Newbie
 
Join Date: Mar 2009
Posts: 17
#3: 2 Weeks Ago

re: Why does this simple for loop create multiple errors?


Ohhhhhhh.... I feel dumb. There was also some brackets missing in my code as well that contributed to that.
Reply