C+ programming analyzing Loop and loop statements. Compile a list of every day o
ID: 3869743 • Letter: C
Question
C+ programming analyzing Loop and loop statements. Compile a list of every day occurrences in life that use loops. For example, traffic light . Secondly, provide an exclamation of really in a context of C#. Lastely,provide an exclamation when you use a loop versus a selection statement? Explain mildly Thank you C+ programming analyzing Loop and loop statements. Compile a list of every day occurrences in life that use loops. For example, traffic light . Secondly, provide an exclamation of really in a context of C#. Lastely,provide an exclamation when you use a loop versus a selection statement? Explain mildly Thank you Compile a list of every day occurrences in life that use loops. For example, traffic light . Secondly, provide an exclamation of really in a context of C#. Lastely,provide an exclamation when you use a loop versus a selection statement? Explain mildly Thank youExplanation / Answer
C++
Looping Statements:
1. ForLoop
2.While Loop
3. Do While Loop
ForLoop:
Suppose if we want to display the elements which are stored in the which of size 100. In these cases, we prefer to use the for loop
Example:
#include <iostream>
using namespace std;
int main() {
int a[5]={1,2,3,4,5};
for(int i=0;i<5;i++)
{
cout<<a[i];
}
return 0;
}
Output:
While
If we want to check the condition before entering into the condition then at the time we prefer to use while condition
Syntax:
while(condition)
{
// statements
}
Example:
#include <iostream>
using namespace std;
int main() {
int a[5]={1,2,3,4,5},i=0;
while(i<5)
{
cout<<a[i];
i++;
}
return 0;
}
Output:
Do-While:
Insted of the condition if we want to diplay the first element then we use the Do while after that it will check condition in which is written in the while.
Syntax:
do
{
statements
}while(condition);
Example:
#include <iostream>
using namespace std;
int main() {
int a[5]={1,2,3,4,5},i=0;
do
{
cout<<a[i];
i++;
}while(i<5);
return 0;
}
Output:
Conditional Statements:
1. If
2. If-else
If-Condition:
In order to check whether the expression is true or false, we use if condition
Syntax:
If(condition)
{
// Statements
}
Example:
#include <iostream>
using namespace std;
int main() {
int a=7,b=6;
if(a>b)
{
cout<<"a is big";
}
return 0;
}
Output:
If-else
if we want to display the false statement also we prefer to use the if else
Syntax:
#include <iostream>
using namespace std;
int main() {
int a=7,b=6;
if(a>b)
{
cout<<"a is big";
}
else
{
cout<<"b is big";
}
return 0;
}
Output:
Selection Statements:
Switch:
If we have multiple values to check then we prefer to use the switch condition
Example:
#include <iostream>
using namespace std;
int main() {
int choice;
cout<<"Enter Your Choice";
cin>>choice;
switch(choice)
{
case 1:
cout<<"The Color Is Red";
break;
case 2:
cout<<"The Color Is Blue";
break;
case 3:
cout<<"The Color Is Green";
break;
default:
cout<<"Invalid Choie";
break;
}
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.