The Artima Developer Community
Sponsored Link

Java Answers Forum
Program not Working(For Loop)

2 replies on 1 page. Most recent reply: Jun 16, 2002 10:01 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
DAYO

Posts: 22
Nickname: done
Registered: Jun, 2002

Program not Working(For Loop) Posted: Jun 11, 2002 6:22 PM
Reply to this message Reply
Advertisement
I have a for loop in which I am reading the content of an array.Also a method is called within the for loop the purpose of this method is to be able to jump to a another array index.
I have written the program as shown below but it does not work.
private class Executionionhandler implements ActionListener
{ public void actionPerformed(ActionEvent event)
{ for(int i=0;i<62;i++)
{ int x=array;
int k=x+2;
look(x);
....
....
}
}

public void look(int j)
{ if(j==5)
i=20;
}

Any idea why or how can I achieve this?


abhijeet

Posts: 21
Nickname: sony
Registered: May, 2002

Re: Program not Working(For Loop) Posted: Jun 11, 2002 10:30 PM
Reply to this message Reply
Hi Dayo,

You have to pass the index of the array inside the for loop (i.e., int x = array) and in the method "look(int j)" you are changing the value of "i" which will not reflect in the for loop because for loop has it's own value for "i" the scope of which is inside for loop only.

abhijeet.

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Program not Working(For Loop) Posted: Jun 16, 2002 10:01 PM
Reply to this message Reply
private class Executionionhandler implements ActionListener
{ public void actionPerformed(ActionEvent event)
{ for(int i=0;i<62;i++)
{ int x=array;
int k=x+2;
if (look(x)> 0) i = look(x);
....
....
}
}

public int look(int j){
int n = -1;
if(j==5)n =20;
return n;
}

Flat View: This topic has 2 replies on 1 page
Topic: print a report with i-net crystalclear ?? Previous Topic   Next Topic Topic: Calling Jsp using <A HREF> tag in html

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use