Learnings of the Week [November 3-7, 2008]
In this week, we tackled about the looping statements.
THE WHILE LOOP
In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement.
For example:
In the C programming language, the code fragment
x=0
while (x<3)
{
printf("x=%d\n",x);
x++;
}
first checks whether x is less than 3, which it is, so it increments x by 1. It then checks the condition again, and executes again, repeating the process until the variable x has the value 3.
THE DO-WHILE LOOP
A do-while loop, sometimes just called a do loop, is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.
The do-while construct consists of a block of code and a condition. First, the code within the block is executed, and then the condition is evaluated. If the condition is true the code within the block is executed again. This repeats until the condition becomes false. Because do-while loops check the condition after block is executed, the control structure is often also known as a post-test loop. Contrast with the while-loop, which tests the condition before the code within the block is executed.
THE FOR LOOP
In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement.
Unlike many other kinds of loops, the for loop is often distinguished by an explicit loop counter or loop variable. This allows the body of the for loop 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.
JUMP STATEMENTS
The Break Statement
A break statement lets you end an iterative statement or a switch statement and exit from it at any point other than the logical end. A break may only appear on one of these statements.
A break statement has the form:
>>-break--;------------------------------------------------------------------------><
In an iterative statement, the break statement ends the loop and moves control to the next statement outside the loop. Within nested statements, the break statement ends only the smallest enclosing do, for, switch, or while statement.
In a switch statement, the break passes control out of the switch body to the next statement ouyside the switch statement.
The Continue Statement
A continue statement ends the current iteration of a loop. Program control is passed from the continue statement to the end of the loop body.
A continue statement has the form:
>>-continue--;---------------------------------------------------------------------><
The continue statement can only appear within the body of an iterative statement.
The continue statement ends the processing of an action part of an iterative statement and moves control the loop continuation portion of the statement.
The goto Statement
A goto statement causes your program to unconditionally transfer control to the statement associated with the label specified on the goto statement.
A goto statement has the form:
>>-goto--label_identifier--;-------------------------------------------------------><
The Exit Function
The purpose of exit function is to terminate the current program with a specific exit code. Its prototype is:
void exit (int exitcode);
Posted by:
RAE ANGELINE S. PALEN
IV - Rizal
THE WHILE LOOP
In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement.
For example:
In the C programming language, the code fragment
x=0
while (x<3)
{
printf("x=%d\n",x);
x++;
}
first checks whether x is less than 3, which it is, so it increments x by 1. It then checks the condition again, and executes again, repeating the process until the variable x has the value 3.
THE DO-WHILE LOOP
A do-while loop, sometimes just called a do loop, is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.
The do-while construct consists of a block of code and a condition. First, the code within the block is executed, and then the condition is evaluated. If the condition is true the code within the block is executed again. This repeats until the condition becomes false. Because do-while loops check the condition after block is executed, the control structure is often also known as a post-test loop. Contrast with the while-loop, which tests the condition before the code within the block is executed.
THE FOR LOOP
In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement.
Unlike many other kinds of loops, the for loop is often distinguished by an explicit loop counter or loop variable. This allows the body of the for loop 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.
JUMP STATEMENTS
The Break Statement
A break statement lets you end an iterative statement or a switch statement and exit from it at any point other than the logical end. A break may only appear on one of these statements.
A break statement has the form:
>>-break--;------------------------------------------------------------------------><
In an iterative statement, the break statement ends the loop and moves control to the next statement outside the loop. Within nested statements, the break statement ends only the smallest enclosing do, for, switch, or while statement.
In a switch statement, the break passes control out of the switch body to the next statement ouyside the switch statement.
The Continue Statement
A continue statement ends the current iteration of a loop. Program control is passed from the continue statement to the end of the loop body.
A continue statement has the form:
>>-continue--;---------------------------------------------------------------------><
The continue statement can only appear within the body of an iterative statement.
The continue statement ends the processing of an action part of an iterative statement and moves control the loop continuation portion of the statement.
The goto Statement
A goto statement causes your program to unconditionally transfer control to the statement associated with the label specified on the goto statement.
A goto statement has the form:
>>-goto--label_identifier--;-------------------------------------------------------><
The Exit Function
The purpose of exit function is to terminate the current program with a specific exit code. Its prototype is:
void exit (int exitcode);
Posted by:
RAE ANGELINE S. PALEN
IV - Rizal


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home