12th Class (HSSC-II) Computer SLO Based Key Point Notes
(National Book Foundation - As Federal Textbook Board, Islamabad Based on National Curriculum Pakistan 2023-2024 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
(National Book Foundation - As Federal Textbook Board, Islamabad
Based on National Curriculum Pakistan 2023-2024 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
{Contact WhatsApp # 03339719149 for Class-XII Computer Science Complete SLO-Based Key Points notes in pdf format as well as in PowerPoint Presentation for preparing/delivering the Lectures}
************************************
************************************
👉👉👉 Computer Science 12th Class Notes (Main Page)
************************************
Unit 4: Control Structures
4.2.1. The for Loop
The for loop is used to execute a statement or set of statements repeatedly for a specified number of times. It is also known as Counter Loop.
Syntax:
for( Initialization; Condition; Increment/Decrement )
{
statement 1;
statement 2;
…
{
statement 1;
statement 2;
…
Working of “for loop”
The number of iterations or repetitions depends on the initialization, condition, and increment/decrement parts of the “for loop”.
The for loop is executed as follows:- First, the initialization part is executed. It is executed only once when the control enters the loop.
- Then the condition is evaluated, if it is TRUE, then the body of the loop is executed.
- After executing the body of the loop, the increment/decrement part is executed that changes the value of a counter variable.
- Then control again transfers the condition part. This process continues while the condition is TRUE. The loop is terminated when the given condition becomes FALSE.
The number of iterations or repetitions depends on the initialization, condition, and increment/decrement parts of the “for loop”.
- First, the initialization part is executed. It is executed only once when the control enters the loop.
- Then the condition is evaluated, if it is TRUE, then the body of the loop is executed.
- After executing the body of the loop, the increment/decrement part is executed that changes the value of a counter variable.
- Then control again transfers the condition part. This process continues while the condition is TRUE. The loop is terminated when the given condition becomes FALSE.
Flowchart of “for loop”
Example # 1:
Write a program that displays “Pakistan” for five times.
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
for ( int n=1 ; n<=5 ; n++ )
{
cout<<“ \n PAKISTAN”;
}
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
for ( int n=1 ; n<=5 ; n++ )
{
cout<<“ \n PAKISTAN”;
}
getch();
}
Example # 2:
Write a program that reads an integer and prints its multiplicative table up to 20.
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n;
cout<<“Enter a number: “;
cin>>n;
for (int i=1; i<=10; i++)
{
cout<<n<<“\tx”<<i<<“\t=“<<n*i<<“\n”;
}
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n;
cout<<“Enter a number: “;
cin>>n;
for (int i=1; i<=10; i++)
{
cout<<n<<“\tx”<<i<<“\t=“<<n*i<<“\n”;
}
getch();
}
Example # 3:
Write a program that inputs a number and finds its factorial using a for loop.
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n,f=1;
cout<<“Enter an integer number: “;
cin>>n;
for (int c =1; c<=n; c++)
{
f = f * c;
}
cout<<“\n\tFactorial of a number is: “<<f;
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n,f=1;
cout<<“Enter an integer number: “;
cin>>n;
for (int c =1; c<=n; c++)
{
f = f * c;
}
cout<<“\n\tFactorial of a number is: “<<f;
getch();
}
👇👇👇👇👇👇👇👇👇
👇👇👇👇👇👇👇👇👇
************************************👉👉👉 Computer Science 12th Class Notes (Main Page)
************************************
Shortcut Links For:
1. 5th Class All Subjects Notes
2. 8th Class All Subjects Notes
3. Easy English Grammar Notes
1. Website for School and College Level Physics 2. Website for School and College Level Mathematics 3. Website for Single National Curriculum Pakistan - All Subjects Notes
© 2023 & onwards Academic Skills and Knowledge (ASK)
Note: Write me in the comments box below for any query and also Share this information with your class-fellows and friends.
1. Website for School and College Level Physics
2. Website for School and College Level Mathematics
3. Website for Single National Curriculum Pakistan - All Subjects Notes
0 Comments
Start Tuition (in Pakistan or Abroad) from Experienced Online Teachers.
Contact WhatsApp for tutoring and Assignment help on +923339719149