Combining Nested FOR Loops and the IF Statements:
The statements inside a nested loop can be any of the valid statement, involving any selection statement. For e.g., there can be an if or if-else statement as the action, or part of action, in the loop.
As an illustration, there is a file known as the datavals.dat that has results recorded from an experiment. Though, some were incorrectly recorded. The numbers are all supposed to be positive. The below script reads from this file into a matrix. It prints the sum from each and every row of only the positive numbers. We will suppose that the file contains integers but will not suppose how many lines are in the file or how many numbers per line.