• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

code statement  RSS feed

 
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
 
Sheriff
Posts: 12343
201
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
 
lowercase baba
Bartender
Posts: 12627
50
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.
 
Marshal
Posts: 6008
415
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
 
Marshal
Posts: 4465
284
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
 
author
Sheriff
Posts: 23588
138
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!