See AnswerAns: Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.
Is there any diff. b/w while() and for()loop?
See AnswerAns: Both for loop and while loop are used to excute one or more lines of code certain number of times. The main differences are as follows. Syntax: While loop:
while(condtion) {
//statements to excute.
} For loop:
for(intialization; condition; Increment or decrement){
// statements to be excuted.
}
Diff. b/w while() and do-while()loop?
See AnswerAns: While Loop: Condition is checked first and also known as entry-control loop. Since condition is checked first, statements may or may not get executed. Do-while Loop: Condition is checked last and also known as exit-control loop. Since condition is checked later, the body satements will execute at least once.
What happen if we use ; at the end of loop?
eg:
for(i=1;i<=2;i++);
{
printf("%d",i);
}
See AnswerAns: The loop will execute without executing any body statement and answer is: 3.
What is Palindrome Number?
See AnswerAns: when a number remains same after the reverse is known as palindrome no. eg. 121
How to check no. is Palindrome or not?
See AnswerAns: First calculate the reverse of a number the check weather it matches with original number or not. if it matches then the no is palindrome otherwise not. eg. Rev=0; N1=N; while(N!=0){ R=N/10; Rev=Rev*10+R; N=N/10; } if(N1==Rev){ cout<<"Palindrome"; else cout<<"not Palindrome";
Explain Break Statement
See AnswerAns: When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop. It can be used to terminate a case in the switch statement.
Explain Continue Statement
See AnswerAns: The continue statement in C programming works somewhat like the break statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between. For the for loop, continue statement causes the conditional test and increment portions of the loop to execute.
How to create infinite for() loop?
See AnswerAns: for(;;)
cout<<"hello";
Program to check whether no. is Prime or not?
See AnswerAns:
When to use nested loops?
See AnswerAns: Nested loops are used where you have to repeat a set of statement repeatedly.