Search Your Question

Showing posts with label Logical. Show all posts
Showing posts with label Logical. Show all posts

I have written for loop from 1 to 10. But when i=7 then then it comes out from loop. I have not written any specific keyword nor exception generated. How it is possible?

ANS :

for(int i=0, i<10:i++)
{
     if(i==6)
          {
              i=10;
           }
}
Here I am trying to iterate from 0 to 9. This loop is iterating till Condition i<10 matches.
Now in iterating, when loop comes i=6 I will make i=10.
So in next iteration, i<10 condition is mismatched. So it comes out from loop.
There is no any keyword used or any exception generated.

Bonus Tip : You can run swift code online here