Showing posts with label Looping in c. Show all posts
Showing posts with label Looping in c. Show all posts

Tuesday, February 22, 2011

do while loop in c



Explanation
of do while loop in c programming language by examples, questions and answers



It is also
called as post tested loop. It is used when it is necessary to execute the loop
at least one time. Syntax:



do {

Loop body

} while (Expression);



Example:



void main(){

int num,i=0;

clrscr();

do{


printf("To enter press 1\n");


printf("To exit press 2

Nested loop in c programming




A loop inside another loop
is known as nested loop. We can write any loop inside any loop in c i.e. we can
write for loop inside the loop or while loop or do while loop etc. For example:



(a)

#include

int main(){

int i,j,k;

for(i=0;i<3;i++){

for(j=0;j<3;j++){


printf(" %d",i+j);


}

}

return 0;

}



(b)

#include

int

while loop in c programming





While loop:



It is pre tested
loop. It is used when we have to execute a part of code in unknown numbers of
times.

Syntax:



while (Expression){

Loop body

}



Properties of while loop:



1. Task of the
expression is to check the condition. Loop will execute until condition is true
otherwise loop will terminate.



2. If any
expression returns zero then condition will false and if it

Looping in c



Explanation
of loops or looping in c programming language by examples and questions



Looping is the
process of repeating of same code until a specific condition doesn�t satisfy.
In c there are three types of loop:



(a)loop

(b)while loop

(c)do while



for loop:



This loop is
used when we have to execute a part of code in finite times. It is per tested
loop. Syntax of for loop:



for (

Break and continue keywords in c programming

Explanation
of break and continue in c programming language by examples and questions and
answers



break:



It is keyword of c
programming. Task of this keyword is to bring the control from out of the loop
in the case of looping. For example:



#include

int main(){

int i;



for(i=0;i<=4;i++){


printf("%d",i);

break;


printf("Label 1");

Saturday, February 19, 2011

Looping questions in java


Objective type mcq questions on loops in java and answers



(1)




public class Loop {

public static void main(String[] args) {

Integer a=012,b;

for(b=0;b<=a;b++);

System.out.print(b);

}

}



What will be the output of above java program?



(a)10

(b)11

(c)12

(d) Compiler error











Answer: (b)



(2)



public class Loop {

public static