0% found this document useful (0 votes)
3 views3 pages

PF Manual 5..

The document outlines a lab session focused on programming fundamentals, specifically loops in C++. It covers the structure and syntax of the for loop, including initialization, condition, and update expressions, as well as providing practice programs and tasks for students. The lab tasks include printing various star patterns using for loops.

Uploaded by

Amna Shiekh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

PF Manual 5..

The document outlines a lab session focused on programming fundamentals, specifically loops in C++. It covers the structure and syntax of the for loop, including initialization, condition, and update expressions, as well as providing practice programs and tasks for students. The lab tasks include printing various star patterns using for loops.

Uploaded by

Amna Shiekh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Faculty of Computing and Information Technology (FCIT)

Department of Computing Indus University, Karachi

NAME OF STUDENT: ID No:

Lab # 065
Programming Fundamentals
Objectives:
Getting familiar with loops.
 The for loop
 Structure of the for loop
 Initialization expression
 Test expression
 Increment expression
 Operational flow chart of for loop

C++ Loops
In computer programming, loops are used to repeat a block of code.

For example, let's say we want to show a message 100 times. Then instead of writing the print
statement 100 times, we can use a loop.

There are 3 types of loops in C++.

 for loop
 while loop
 do...while loop

C++ for loop


The syntax of for-loop is:

for (initialization; condition; update) {


// body of-loop
}

Here,
 initialization - initializes variables and is executed only once
 condition - if true, the body of for loop is executed
if false, the for loop is terminated
 update - updates the value of initialized variables and again checks the condition
Faculty of Computing and Information Technology (FCIT)
Department of Computing Indus University, Karachi

NAME OF STUDENT: ID No:

Structure of for Loop

Flow Chart of for loop

Practice Program-1(Printing Numbers From 1 to 10)


Faculty of Computing and Information Technology (FCIT)
Department of Computing Indus University, Karachi

NAME OF STUDENT: ID No:

Practice Program-2(Display a text 5 times)

Practice Program-3(Find the sum of first n natural numbers)

LAB TASK:
Q1) Print a diamond, pyramid and half pyramid star pattern, by using for loop.

You might also like