Loops in c Programming
The versatility of the computer lies in its ability to perform a set of instructions repeatedly. This involves repeating some portion of the program either a specified number of times or until a particular condition is being satisfied. This repetitive o through a loop control instruction.
There are three methods by way of which we can repeat a part of a program. They are:
(a) Using for a statement
(b) Using a while statement
(c) Using a do-while statement
While loop:
The while loop is i simple example, w deally suited for such cases. Let us look at a hich uses a while loop. The flowchart shown count = 1 ; below would help you to understand the operation of the while loop.
There are three methods by way of which we can repeat a part of a program. They are:
(a) Using for a statement
(b) Using a while statement
(c) Using a do-while statement
While loop:
The while loop is i simple example, w deally suited for such cases. Let us look at a hich uses a while loop. The flowchart shown count = 1 ; below would help you to understand the operation of the while loop.
For loops:
In computer science a for-loop (or simply for loop) is a programming language control statement for specifying iteration, which allows code to be executed repeatedly. The syntax of a for-loop is based on the heritage of the language and the prior programming languages it borrowed from, so programming languages that are descendants of or offshoots of a language that originally provided an iterator will often use the same keyword to name an iterator, e.g., descendants of ALGOL use "for", while descendants of Fortran use "do." There are other possibilities, for example COBOL which uses "PERFORM VARYING".
Unlike many other kinds of loops, such as the while-loop, the for-loop is often distinguished by an explicit loop counter or loop variable. This allows the body of the for-loop (the code that is being repeatedly executed) to know about the sequencing of each iteration. For-loops are also typically used when the number of iterations is known before entering the loop. For-loops are the shorthand way to make loops when the number of iterations is known, as a for-loop can be written as a while-loop.
for (int i=0; i<100; i++) // Prints the numbers 0 to 99 (and not 100), each separated by a space. { System.out.print(i); System.out.print(' '); } System.out.println();
The name for-loop comes from the English word for, which is used as the keyword in most programming languages to introduce a for-loop. The term in English dates to ALGOL 58 and was popularized in the influential later ALGOL 60; it is the direct translation of the earlier German für, used in Superplan (1949–1951) by Heinz Rutishauser, who also was involved in defining ALGOL 58 and ALGOL 60. The loop body is executed "for" the given values of the loop variable, though this is more explicit in the ALGOL version of the statement, in which a list of possible values and/or increments can be specified.
In FORTRAN and PL/I though, the keyword DO is used and it is called a do-loop, but it is otherwise identical to the for-loop described here and is not to be confused with the do-while loop.
1 Comment:
thanks for give me c loops imforamatons
Post a Comment