Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A question on "for" loop
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Johnny19931993




PostPosted: Sun Nov 15, 2009 8:16 pm   Post subject: A question on "for" loop

I'm new to java and I've encountered a problem when I was using the for loop
Apparently I can't assign a variable to it as the initial value
like this
Java:

int a = 100;
for (int i = a; i == 101; i++)
{
Statement;
}

For example, if the statement was to output some string, it doesn't do it
can someone help me?
(I am using dr.java)
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sun Nov 15, 2009 9:09 pm   Post subject: RE:A question on "for" loop

This for loop will only execute while i == 101. So it will check, does i = 101? No? Okay, skip this part!

Try for (int i = a; i <= 101; i++)
andrew.




PostPosted: Sun Nov 15, 2009 9:29 pm   Post subject: Re: A question on "for" loop

Johnny19931993 @ Sun Nov 15, 2009 8:16 pm wrote:

Apparently I can't assign a variable to it as the initial value

That's not the problem, as insectoid said, it is checking the condition in which to continue.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: