Forums Register Login
code statement
hi there,
please could anyone explain me about following lines: 4,5,6 in following program.

What do you think it's doing? Apart from the misleading name, it's a pretty simple piece of code. Did you go through the Java Tutorial section about the for-statement? The tutorial material should give you enough to understand the code you're asking about. Please ShowSomeEffort (←click)
i checked but there is not any for with if statement.
so please could you explain what happens if for condition comes with if branching???
There is no if with for statement in the code you show.

There is a for loop, that has a single 'thing' in it. that thing will run multiple times, depending on the conditions in the for statement. Perhaps it would help if you put in the braces.

the one thing inside the for body happens to be...an if-statement.
(1 like)
Raj Gurung, look how right indentation makes your code more readable and understandable.
Hi there,
I have noticed in this 4,5,6 line that if if condition is not true then else condition is executing. how come it is like this without writing else condition?

Raj Gurung wrote:... then else condition is executing ...

What else condition?
what I mean to say is, what happens when if condition is false in program below?


Raj Gurung wrote:Hi,
what I mean to say is, what happens when if condition is false in program below?

When the condition is false, the "if" block doesn't run. So, it runs the code after the "if" block, which in this case, is the next iteration of the "for" loop.


This thread has been viewed 461 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 15, 2018 19:18:19.