Consider the following:
for (int counter = 1; counter < 1; counter -)
How many times will the loop execute?
Consider the following:
for (int counter = 1; counter < 1; counter -)
How many times will the loop execute?
zero or infinite....I think zero
How about you put a print inside the loop ?
The Loop will not be executed. The condition for the Loop fails as 1 < 1 is false
It will not be executed becuase it cannot be compiled.counter -
is not valid Java
As JamesCherrill pointed out, there is a syntax error, but if you change it to for (int counter = 1; counter < 1; counter--)
, it will not run, because counter
is initialised to 1, the condition checks if it is < 1, so it fails, and the loop doesn't run. If you are thinking about writing an infinite loop, initialise counter
to 0.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.