By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
SA Jobs SearchSA Jobs Search
  • Jobs
  • Employers/Agencies
  • Career Advice
    • Skills
    • News
  • NECTA Results
  • SA Articles
    • SASSA Updates
  • Scholarships
  • Technology
Search
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
Reading: The four parts of each loop in C++
Share
Sign In
Notification Show More
Latest News
High Paying Jobs In Canada For Immigrants
Career Advice
AKA Accused Of Killing Nellie Tembe In Leaked Court Documents
AKA Accused Of Killing Nellie Tembe In Leaked Court Documents
Entertainment News
Vumoo: Free Movie Streaming
Tech Tips
What Are Basic Skills In Education | How to develop the 10 key skills you need to work in Education
Education, Colleges & Institutes
Is Capital Goods a Good Career Path?
Productivity
Aa
SA Jobs SearchSA Jobs Search
Aa
  • Home
  • Home
  • Home
  • Home
  • Jobs
  • Resume Home
  • Jobs
  • Jobs
  • Job Listing Home
  • Search Map Home
  • RecruitExpert Home
  • Career Home
  • Companies
  • Job Categories Home
  • Resumes
  • Candidate Home
  • #17001 (no title)
  • Pages
  • Hiring Home
  • Jobs
  • Style 1
  • Style 2
  • Style 3
  • Style 4
  • Companies
  • Companies
  • Resumes
  • Resumes
  • Jobs
  • Pages
  • Pages
  • Style 1
  • Style 2
  • Style 3
  • Style 4
  • Companies
  • Companies
  • Resumes
  • Resumes
  • Pages
  • Pages
Search
  • Disclaimer
  • About Us
  • Privacy Policy
  • Contact Us
Have an existing account? Sign In
Follow US
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
Education, Colleges & Institutes

The four parts of each loop in C++

Admin
Last updated: 2021/12/06 at 3:35 AM
Admin
Share
SHARE

The simplest control structure in C++ is the while loop. Although it’s not completely flexible, the for loop is actually the more common of the two – it has a certain elegance that’s hard to ignore. You will notice that most episodes consist of four basic parts.
Setup: Setup usually involves declaring and initializing an increment variable. This generally happens before the period.
Test expression: The expression inside the while loop that will make the program execute the loop or exit and continue. This always occurs inside the parentheses following the while keyword.
Body: This is the code inside the parentheses.
Increment: This is where the increment variable is incremented. This usually happens at the end of the body.
In the case of the factor program, the four parts looked like this:
int nValue = 1; // the setup
while (nValue <= nTarget) // the test expression
{ // the body
cout << nAccumulator << ” * ”
<< nValue << ” equals “;
nAccumulator = nAccumulator * nValue;
cout << nAccumulator << endl;
nValue++; // the increment
}
The for loop incorporates these four parts into a single structure using the keyword for:
for(setup; test expression; increment)
{
body;
}
The flow is shown graphically here:
image0.jpg
 
1. As the CPU comes innocently upon the for keyword, control is diverted to the setup clause.
2. Once the setup has been performed, control moves over to the test expression.
3. (a) If the test expression is true, control passes to the body of the for loop.
(b) If the test expression is false, control passes to the next statement after the closed brace.
4. Once control has passed through the body of the loop, the CPU is forced to perform a U-turn back up to the increment section of the loop.
5. That done, control returns to the test expression and back to Step 3.
This for loop is completely equivalent to the following while loop:
setup;
while(test expression)
{
body;
increment;
}

You Might Also Like

What Are Basic Skills In Education | How to develop the 10 key skills you need to work in Education

Ardhi University (ARU) Entry Requirements 2022-2023

FORM FIVE SELECTION 2022-2023

Fluoxetine Side Effects in Females

TAGGED: for loop c++ example program with output pdf, for loop counter c++, loop structure in c++ programming, parts of a for loop python, parts of for loop in c, The four parts of each loop in C++, what are the 3 parts of a for loop?, what are the four components of a loop, what is for loop in c++

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share this Article
Facebook Twitter Copy Link Print
Share
Previous Article How to avoid introducing errors in C ++ programming
Next Article Performance and Big Data
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow
banner banner
Create an Amazing Newspaper
Discover thousands of options, easy to customize layouts, one-click to import demo and much more.
Learn More

Latest News

High Paying Jobs In Canada For Immigrants
AKA Accused Of Killing Nellie Tembe In Leaked Court Documents
AKA Accused Of Killing Nellie Tembe In Leaked Court Documents
Vumoo: Free Movie Streaming
What Are Basic Skills In Education | How to develop the 10 key skills you need to work in Education
//

We influence 20 million users and is the number one business and technology news network on the planet

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

[mc4wp_form id=”1616″]

SA Jobs SearchSA Jobs Search
Follow US

© 2023 SA Jobs Search. All Rights Reserved.

Removed from reading list

Undo
Welcome Back!

Sign in to your account

Register Lost your password?