R4R
Right Place For Right Person TM
 
R4R CC TutorialsC Basic Tutorials1.5Looping Statements
 
previous

Home

Next

 

Looping Statements: In looping statement how many times the action is to be perform.
Ex. of looping statements :

1. While loop:

while ( expression )
{
Single statement

or
Block of statements;
}

2. Do While loop:

do

{
Single statement
or

Block of statements;
}
while
(expression);

3. For loop :

for
( expression1; expression2; expression3)
{
Single statement
or
Block of statements;
}

Nesting Of Loops In C

Nested loop, means one loop in the other loop.
For Example :
for (i=0; i<10; ++i)
{
for
(j=0; j<i; ++j)
   {
printf ("i=%d, j=%d\n", i, j);

    }
}

Multiple Initialization In A For Loop

This means , we can initialize more than one variable within one loop.

For Example :
for
(int i=0,int j=10 ; i<5&&j<10 ; i++ , j--)
{
some block of statements
}

Odd Loop In C

Loop is define as "the repetition of data according to the given conditions " so odd loop is that loop which only repeat the odd numbers & it leave the even numbers".

Break Statement In C

The break command allows you to terminate and exit a loop (that is, do, for, and while). You can place a break command only in the body of a looping command or in the body of a switch command. The break keyword must be lowercase and cannot be abbreviated.
In a looping statement, the
break command ends the loop and moves control to the next command outside the loop. Within nested statements, the break command ends only the smallest enclosing do, for, switch, or while commands.
In a
switch body, the break command ends the execution of the switch body and transfers control to the next command outside the switch body.
For Example :
#include <stdio.h>
#include <conio.h>
void main() 
{
  clrscr();
  
int n;
printf(" \nEnter the number :");
    scanf("%d", &n);
    
if (n < 0) 
    {
     
 break
;
    }
}

The Continue Statement In C

The continue statement can only appear in a loop body. It  skipped the rest of the statement body in the loop.
Syntax :
continue;

For Examples:
for (loop=0;loop<100;loop++)
 {
  if (loop==50)
    continue;
  printf ("%i\n", loop);
 }
Output:
The numbers 0 through 99 are printed except for 50.

goto Statement In C

goto is used for jumping from one statement to another. It is very  negative approch to use goto in our program due its inherent properties of breaking the code.
Syntax : goto label;
 

The goto statement is often combined with the if statement.
Syntax : if condition then goto label;
For Example :
#include <stdio.h>
#include <conio.h>
int main()
{

  int n = 0;
  loop: ;
 
  printf("\n%d", n);
  n++;
  if (n<10)
{

    goto loop;
  }
  getch();
  return 0;
}
Output will be displayed as:
0
1
2
3
4
5
6
7
8
9

Disadvantages Of goto Statement

Goto should not really be used in programs at all because they have a tendency to make code unstructured and they make programs difficult to manage when they become significantly large.
 

previous

Home

Next


Tolal:0 Click:
Show All Comments

Post Your Comments

Your Name:

Your Email ID :
Comments :
URL
  =* Enter SUM

Tutorials,Examples,Questions and Answer

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R