[go: up one dir, main page]

0% found this document useful (0 votes)
13 views4 pages

CS2 5.4.2 Nested Loop

This module focuses on understanding and constructing nested loops in C++ programming, including their syntax and flowcharts. Students are expected to create a program that generates a numeric triangle pattern based on user input. The lesson includes references for further reading on nested loops.

Uploaded by

kch.09082014
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)
13 views4 pages

CS2 5.4.2 Nested Loop

This module focuses on understanding and constructing nested loops in C++ programming, including their syntax and flowcharts. Students are expected to create a program that generates a numeric triangle pattern based on user input. The lesson includes references for further reading on nested loops.

Uploaded by

kch.09082014
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
You are on page 1/ 4

Subject Code: CS2 Introduction to Computational Thinking

Module Code: 5.0 More Logical Control Structure


Lesson Code: 5.4.2 Nested Loop
Time Frame: 30 minutes

TARGET Time Allotment: 1 minute

After completing this module, you are expected to:


• Understand the structure of nested loops and how to use them
• Construct a nested loop program that solves a specific tasks
• Test and debug a nested loop program

HOOK Time Allotment: 5 minutes

Nested loop in C++ programming is identified as loop statement inside a loop statement.
Nested loops maybe in a form of a nested WHILE, FOR and DO-WHILE loop. The basic
syntax and flowchart for the nested WHILE loop are:

initialization;
while(condition

initialization
while(condition

statement(s)
updateExpression

statement(s)
updateExpression

While for the nested FOR loop, the syntax and flowchart is:

for ( initialization; condition; updateExpression )


for ( initialization; condition; updateExpression )
statement(s)

statement(s)
}

LG-UBALDO-CS2-5.4.1.2 CS 2 Page 1 of 4
{

NAVIGATE Time Allotment: 5 minutes

Programming Exercise

Numeric Triangle Pattern

Based on the example given on the previous module, create a program that replicated
the triangle pattern shown. Try to look at the examples closely and think of an algorithm
that replicates the outputs. Let’s see if you still look at Triangle problems the same way
after this problem.

Input:
Integer value n.

Output:
A triangle based on the inputted value of n.

Sample Input and Outputs:

Input Output
3 *
**
***
4 *
**
***
****
7 *
**
***
****
*****
Modified problem from: codechum.com

Note: This is a graded assessment

LG-UBALDO-CS2-5.4.1.2 CS 2 Page 2 of 4
KNOT Time Allotment: 5 minutes

A loop can have another loop inside and this structure is called nested loop. We can
implement a nested FOR, WHILE or DO-WHILE loops. We can put any kind of loop
inside any kind of loop.

REFERENCES

Nested Loop in C++. (2002). Retrieved from Educba: https://www.educba.com/nested-loop-in-c-plus-


plus/

Nested Loops in C++ with Examples. (2019, December 03). Retrieved from GeeksforGeeks: https://
www.geeksforgeeks.org/nested-loops-in-c-with-examples-2/

Parewa Labs Pvt. Ltd. (n.d.). C++ Nested Loop. Retrieved from Programiz: https://
www.programiz.com/cpp-programming/nested-loops

Shrestha, S. (2021). Nested Loops in C++ Programming. Retrieved from Programtopia: https://
www.programtopia.net/cplusplus/docs/nested-loops

LG-UBALDO-CS2-5.4.1.2 CS 2 Page 3 of 4
Prepared by: ROMAR JAN M. UBALDO Reviewed by: Trextan Thaddeus Sanchez
Position: SSTIII Position: SSTIII
Campus: PSHS-IRC Campus: PSHS-SMC

© 2020 Philippine Science High School System. All rights reserved. This document may contain proprietary informa on and may only be
released to third par es with the approval of management. Document is uncontrolled unless otherwise marked; uncontrolled
documents are not subject to update no ca on.

LG-UBALDO-CS2-5.4.1.2 CS 2 Page 4 of 4
ti
ti
fi
ti
ti

You might also like