![]() ![]() ![]() ( As a result, our loop doesn't carry out any operations again and our final-expression is never executed also ) ( No it isn't ☹️, 3 is not less than 3, it is rather, equal to 3, therefore, the condition returns false ) ( Yes it is □, 2 is less than 3, therefore, the condition returns true ) ( Yes it is □, 1 is less than 3, therefore, the condition returns true ) sum is therefore = 0 + 1.Īccording to the final-expression, variable i is incremented by 1. ( Yes it is □, 0 is less than 3, therefore, the condition returns true ) While i is less than a, the sum keeps increasing by 1. The for.loop operation initializes a variable i to 0, states a condition that the statements of the loop should only be executed while the i variable is less than the a variable, states a final-expression that after each operation, increase the i variable by 1 ( i++) and also leaves a statement to be executed which is incrementing the sum by 1. What our program (or rather, the function) simply does is to set the variable a to 5 and sum to 0. ![]() I placed the for loop in a function so that the codes there are only executed when the function is called - the example function. Enter fullscreen mode Exit fullscreen mode ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |