Sunday, January 13, 2019

C Programming Language and for loop

C Programming language allows developers to write loops using for and while.

Consider the below C code in which for loop being used.
Code Snippet 1




In the above code the test expression uses two conditions with a comma separator.

Sometimes the developers might assume that the code in the for loop is not executed when any condition fails.But the for loop always executes when first condition is True or False and the Second condition is True. The for loop is exited when the Second condition Fails.

Hence the for loop exits when the loop value becomes 2 for the code in Code Snippet 1
Output for Code Snippet 1


Now, just interchange the two conditions and see the Result after executing the code.
Code Snippet 2  


Output for Code Snippet 2

No comments:

Post a Comment