In Turbo C++, a for
loop is a control flow
statement that allows
code to be executed
repeatedly.
for (initialization;
condition;
increment/decrement) {
// code to be
executed
}
Initialization: This is where you initialize your
loop counter. This statement is executed only
once.
Condition: This is a boolean expression that the
system checks before each loop iteration. If it’s
true, the loop continues; if it’s false, the loop
ends.
Increment/Decrement: This statement is
executed at the end of each loop iteration.
#include<iostream.h>
#include<conio.h>
void main() {
clrscr();
for(int i = 1; i <= 10; i++) {
cout << i << "n";
}
getch();
return 0;
}
A while loop in programming is a control flow
statement that allows a certain piece of code to
be executed repeatedly based on a given
Boolean condition. The while loop can be
thought of as a repeating if statement. The
code inside the loop is executed, and then the
Boolean condition is evaluated. If the condition
is true, the code inside the loop is executed
again. This repeats until the condition becomes
false.
while(condition) {
// code to be
executed
}
int i = 0;
while(i < 5) {
cout << i << "n";
i++;
}
Condition: This is a Boolean expression that is
checked before each iteration of the loop. If the
condition is true, the loop continues; if it’s
false, the loop ends and control passes to the
next line of code after the loop.
Code to be executed: This is the code that is
run for each iteration of the loop, as long as the
condition is true.
A do-while loop in Turbo C++ is a
variant of the while loop. Unlike the
while loop, the do-while loop
checks the condition after
executing the statements within the
loop. This means that the do-while
loop will execute its statements at
least once, even if the condition is
false.
do {
// code to be
executed
} while(condition);
#include<iostream.h>
#include<conio.h>
main() {
clrscr();
int i = 1;
do {
cout << i << "n";
i++;
} while(i <= 5);
getch();
return 0;
}

Introduction to programming in C++ : Loop Structure.pptx

  • 2.
    In Turbo C++,a for loop is a control flow statement that allows code to be executed repeatedly.
  • 3.
  • 4.
    Initialization: This iswhere you initialize your loop counter. This statement is executed only once. Condition: This is a boolean expression that the system checks before each loop iteration. If it’s true, the loop continues; if it’s false, the loop ends. Increment/Decrement: This statement is executed at the end of each loop iteration.
  • 5.
    #include<iostream.h> #include<conio.h> void main() { clrscr(); for(inti = 1; i <= 10; i++) { cout << i << "n"; } getch(); return 0; }
  • 6.
    A while loopin programming is a control flow statement that allows a certain piece of code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement. The code inside the loop is executed, and then the Boolean condition is evaluated. If the condition is true, the code inside the loop is executed again. This repeats until the condition becomes false.
  • 7.
  • 8.
    int i =0; while(i < 5) { cout << i << "n"; i++; }
  • 9.
    Condition: This isa Boolean expression that is checked before each iteration of the loop. If the condition is true, the loop continues; if it’s false, the loop ends and control passes to the next line of code after the loop. Code to be executed: This is the code that is run for each iteration of the loop, as long as the condition is true.
  • 10.
    A do-while loopin Turbo C++ is a variant of the while loop. Unlike the while loop, the do-while loop checks the condition after executing the statements within the loop. This means that the do-while loop will execute its statements at least once, even if the condition is false.
  • 11.
    do { // codeto be executed } while(condition);
  • 12.
    #include<iostream.h> #include<conio.h> main() { clrscr(); int i= 1; do { cout << i << "n"; i++; } while(i <= 5); getch(); return 0; }