Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 12007
196
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: 12624
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.
 
Sheriff
Posts: 5691
393
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: 4407
281
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: 23507
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
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!