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




thanks
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???
thanks
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?
thanks
 

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


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



thanks
 

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.

Henry

This thread has been viewed 442 times.

All times above are in ranch (not your local) time.
The current ranch time is
Sep 24, 2018 12:07:13.