C++

Topic: Control Flow

Definition While statements

The while loop allows programs to repeat a statement or series of statements, over and over, as long as a certain test condition is true.  The format is shown in the box to the right.The test condition must be enclosed in parentheses.  The block of code is called the body of the loop and is enclosed in braces and indented for readability.  (The braces are not required if the body is composed of only ONE statement.)  Semi-colons follow the statements within the block only.When a program encounters a while loop, the test condition is evaluated first.  If the condition is TRUE, the program executes the body of the loop.  The program then returns to the test condition and reevaluates.  If the condition is still TRUE, the body executes again.  This cycle of testing and execution continues until the test condition evaluates to 0 or FALSE.  If you want the loop to eventually terminate, something within the body of the loop must affect the test condition.  Otherwise, a disastrous INFINITE LOOP is the result!  ;-(The while loop is an entry-condition loop.  If the test condition is FALSE to begin with, the program never executes the body of the loop.The following program fragment prints and counts the characters of a string array:apstring name="Corky"; i = 0;            //begin with the first cell of array while (i< name.length( ))    // loop test condition {       cout<< name[ i ] << endl;  //print each character       i++;                            //increment counter by 1 } cout << "There are " << i << " characters.\n"; \*This last cout prints when the test condition is false and the loop terminates*\

Browse random answers:

Write programs using nested loops to produce the following design: * * * * * * * * *
What is Downcasting ?
#include <iostream>using namespace std;int foot (int x, int y) {return((x+y)*3);}int main() {int a = 1;int b = 2;do {cout << foot(b,a);} while ( b < a);return 0;}
Differentiate between the message and method.
What are the decision making statements?
What is the output with using decision making statements method?void main(){            int i;            char a[]="\0";            if(printf("%s\n",a))                        printf("Ok here \n");            else                        printf("Forget it\n");}
What are conditional operators?
What is the output with using conditional operators method ?void main()         {if(~0 == (unsigned int)-1)printf(“You can answer this if you know how values are represented in memory”);         } 
What is the default scope of if statement?
What is the output?main(){            float me = 1.1;            double you = 1.1;            if(me==you)printf("I love U");else                        printf("I hate U");}
 Is it necessary if block always nested with else block?
What is the output?int i,j;            for(i=0;i<=10;i++)            {            j+=5;            assert(i<5);            }
What is the purpose of break and continue statement?
What is the output?main()            {            int k=1;            printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");            }
What is the control flow?
What is the purpose of using do-while loop?
At which condition switch statement is used?
What is the subtle error in the following code segment?void fun(int n, int arr[]){int *p=0;int i=0;while(i++<n)            p = &arr[i];*p = 0;}
What is the difference between while and do while?
What is the output?main()   {            int i=10,j=20;               j = i, j?(i,j)?i:j:j;             printf("%d %d",i,j);}
What is difference between for loop and while loop ?
hat is the output?main(){while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”);    }
What are Structured programming and C++ flow contro?l
Example of if-else statement?
Example of if-else statement example
Example of else-if construct(else-if ladder)
Example of while loop?
Example of for loop?
Example of break statement?
Example of continue statement
Definition Logical And && ?
Definition Logical Or || 
Definition Logical Not ! ?
Definition Logical Equals == ?
Definition  Logical Not Equal != ?
Definition Strictly greater than > ?
Definition Greater than or equal to >=?
Definition Strictly less than < ?
Definition Less than or equal to <= ?
Definition Modulo Division % ?
Definition Incrementer ++ ?
Definition Decrementer -- ?
Definition If statements ?
 If Statement Syntax
Definition While statements
Describe Selection – if and switch using C++.?
Explain Loops – While loop, Do-while loop, for loop.
Explain The break statement