Hello everyone! I'm a student and soon my exams will start.. One of my courses is Programming. We have to understand all kinds of concepts among 6 languages (FORTRAN, Algol, Pascal, LISP, Smalltalk and Prolog) He gave us some example questions of what he could ask during the oral exam. One of the questions was: "What is nesting? Give an example of it in a for loop in Pascal + what is the problem there?" Ok, I understand what nesting is, but I don't know what the problem might be by nesting in a forloop? Does someone have an idea? Thanks a lot in advance!
Nested for loop in pascal is rarely used due to confusion of Begin and End. (Begin only comes if there exists any code and End comes if and only if Begin is there). Consider following definition. for {loop counter} := {original value} to {final value} do {Begin-if required} {[B]code if any..begin should be included[/B] (i.e more than one action)} for {loop counter} := {original value} to {final value} do {Begin-if required} {[B]code..if more than one action, include begin in the second for loop[/B]} {End; - [B]if begin is included in the second for loop[/B])} {[B]code if any..begin should be included in the first for loop[/B]} {End; - [B]if begin is included in the first for loop[/B])} Code (markup):
nesting can be explained simpler in html Properly nested <i><b></b></i> HTML: Not nested properly <i><b></i></b> HTML: