• Post Reply Bookmark Topic Watch Topic
  • New Topic

code statement  RSS feed

 
Raj Gurung
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
please could anyone explain me about following lines: 4,5,6 in following program.




thanks
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Raj Gurung
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj Gurung, look how right indentation makes your code more readable and understandable.
 
Raj Gurung
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj Gurung wrote:... then else condition is executing ...

What else condition?
 
Raj Gurung
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
what I mean to say is, what happens when if condition is false in program below?



thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!