Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for loop

 
Mohd Abrar Khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the third part of the for loop is the iteration, i just wanted to know in the above code does the line 3 evaluates the output or its just that the iteration starts after the condition is passed.

i tried running without line 3 and the result is never ending, so how does the condition operator gets checked and starts the iteration.

Abrar
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the condition.

1) set a to 1.
2) Check if b is equal to 1.
3) enter the loop and process it.
4) finish off the third part of the iteration i.e print.

For the next run, a is still 1 while b is 2 ( due to b=b-a). This will print once more.

For the third run, a =1 and b is 1 too. the condition fails and the loop exits.

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is same as your code.... Mohd Abrar Khan, Your question isn't clear well.......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic