1
[Java] What does a semicolon do directly after a "for" loop?
Author Summary
pds12345 is
in
Java
Post Body
In my text book it simply states that a semicolon after a "for" loop causes to loop to only execute once, and does not provide much in the way of an example.
int x = 0;
for (int j = 1; j <= 79; j );{
x ;
}
System.out.println(x);
I placed this in and ran it and the output was x = 1, which I expected. Now I am given this code...
int p = 6;
int m = 20, j;
for (j = 1; j < p; j );{
m = m j * j;
}
System.out.println(m);
and when I run it, I get 56 back. I want to know how 56 was taken out of this, because if it was only run once, would it not return 21?
Thanks for any help on treating my understanding of this.
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
8,864
Link Karma
399
Comment Karma
8,066
Profile updated: 3 days ago
Posts updated: 8 months ago
Subreddit
Post Details
Location
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 11 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnprogra...