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

New Updates

10:New Updates
Tutorials,examples and Interview Questions with answers
Posted By: Shashi     Posted Date:02.10.14

9:C# Tutorials,C# examples and C# Interview Questions with answers
R4R provide C# Tutorials,C# examples and C# Interview Questions with answers. Through R4R you can develop a small application and small programs.We cover C# Tutorials,C# examples and C# Interview Questions and answers for freshers as well experienced programmer.
Posted By: Shashi     Posted Date:11.17.13

8:Java/J2EE(Servlet,JSP,JNDI,Struts,Spring,Hibernate,EJB,JSF,JMS,Web-Services)
In this section R4R covers Java/J2EE(Servlet,JSP, JNDI, Struts, Spring, Hibernate, EJB,JSF,JMS,Web-Services) Tutorials with Examples.R4R provide Java/J2EE (Servlet,JSP, JNDI,Struts, Spring, Hibernate, EJB, JSF, JMS, Web-Services) Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.13.13

7:CoreJava Tutorials , CoreJava Examples and CoreJava Interview Questions with answers
In this section R4R covers CoreJava Tutorials with CoreJava Examples. R4R covers CoreJava programming concept in easy way. R4R provide CoreJava Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.04.13

6:Microsoft.net Technology ASP.NET,c# ,ADO.NET,WCF,WPF,Silverlight ,VB.net
R4R provides Microsoft Technologies(like ASP.NET,c# ,ADO.NET,WCF,WPF, Silverlight and VB.ne)Tutorials with Examples,programming concept and Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.04.13

5:J2me Tutorials concept with Examples with Netbean IDE and J2ME Application Examples.
R4R cover basic J2me Tutorials concept with Examples and provide a way to develop J2me programming concept in easy way. R4R provide J2me Interview Questions with answers.R4R provide J2me Languages study materials with examples uing Netbean IDE and J2ME Application Examples.
Posted By: Shashi     Posted Date:10.30.13

4:J2me Tutorials concept with Examples ith netbean IDE and J2ME Application Examples.
R4R cover basic J2me Tutorials concept with Examples and provide a way to develop J2me programming concept in easy way. R4R provide J2me Interview Questions with answers.R4R provide J2me Languages study materials with examples uing Netbean IDE and J2ME Application Examples.
Posted By: Shashi     Posted Date:10.30.13

3:Java ebooks , Java tutorials , Java examples , Java interview questions and answers
R4R provides study materials for Java/j2EE technologies. R4R covers core java, advanced java, servlet, JSP, Struts, Spring, Hibernate, EJB, JSF, J2ME, ANT, JUnit and Some APIS .R4R also provides ebooks,tutorials,examples, interview questions and answers.
Posted By: Shashi     Posted Date:10.30.13

2:Learn basic C++ Tutorials with Examples , C++ Interview Questions with answers
R4R is a free E-learning website.You can learn basic C++ Tutorials with Examples , C++ Interview Questions with answers and also some hot topics.
Posted By: Shashi     Posted Date:10.30.13

1:C Tutorials with Example C subjective and objective interview questions and answers
R4R provide C Tutorials with Example and also provides C subjective and objective interview questions and answers.You can learn C in easy way.We cover basics of C here and give some examples.
Posted By: Shashi     Posted Date:10.30.13

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R