0% found this document useful (0 votes)
99 views

C1102-WB - Week9

This document discusses looping control structures in programming. It defines terms related to loops like loop control variable, definite and indefinite loops, nested loops, and outer and inner loops. It provides examples of pseudocode using for, while, and do-while loops and asks the reader to determine the output. Exercises are included to design logic for programs that use loops, such as a movie rating program, a program to calculate sums of numbers, and programs to output numbers in specific patterns.

Uploaded by

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

C1102-WB - Week9

This document discusses looping control structures in programming. It defines terms related to loops like loop control variable, definite and indefinite loops, nested loops, and outer and inner loops. It provides examples of pseudocode using for, while, and do-while loops and asks the reader to determine the output. Exercises are included to design logic for programs that use loops, such as a movie rating program, a program to calculate sums of numbers, and programs to output numbers in specific patterns.

Uploaded by

alifresky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

C1102 Introduction to Computer Systems and Programming Week 9

Week 9: Looping Control Structure

Summary Layout

 Understanding the Advantages of Looping


 Using a Looping Control Variable
 Nested Loops
 Avoiding common loop mistakes
 Using a for, do-while and while loop
 Common Loop Applications

1. Looping
Define following terms:

a. Loop control Variable……………………………..

b. Definite Loop………………………….

c. Counter–controlled loop………………………………….

d. Indefinite Loop……………………………..

e. Nested loops………………………

f. Outer loop…………………………………

g. Inner loop…………………………………

h. Stub…………………………………….

2. Exercises

2.1 What is the output by each of the Pseduocode segments?

a. b. c.

a=1 d=4 g=4


b=2 e=6 h=6
c=5 f=7 while g<h
while a<c while d > f g=g+1
a=a + 1 d=d + 1 endWhile
b=b + c e=e - 1 Output g,h
endWhile endWhile
Output a,b,c Output d,e,f
C1102 Introduction to Computer Systems and Programming Week 9

d. e. f.

j=2 j=2 p=2


k=5 k=5 q=4
n=9 m=6 while p<q
while j<k n=9 Output “Adios”
m=6 while j<k r=1
while m<n while m<n while r<q
Output “Goodbye” Output “Hello” Output “Adios”
m=m+1 m=m+1 r=r+1
endWhile endWhile endWhile
j=j+1 j=j+1 p=p+1
endWhile endWhile endWhile

2.2

a. Design a program for the Hollywood Movie Rating Guide, which can be installed in a
kiosk in theaters. Each theater patron enters a value from 0 to 4 indicating the
number of stars that the patron awards to the guide’s featured movie of the week. If
a user enters a star value that does not fall in the correct range, prompt the user
continuously loop until a correct value is entered. The program executes
continuously until the theatre manager enters a negative number to quit. At the end
of the program, display the average star rating of the movie.
C1102 Introduction to Computer Systems and Programming Week 9

b. Modify the movie rating program so that a user gets three tries to enter a valid
rating. After three incorrect entries, the program issues an appropriate message and
continues with a new user.

2.3

Design the logic for a program that allows a user to enter a number. Display the sum of
every number from 1 through the entered number.
C1102 Introduction to Computer Systems and Programming Week 9

2.4
a. Design the logic for a program that outputs numbers in reverse order from 25 down
to 0.

b. Design the logic for a program that outputs every even number from 2 to 100.

c. Design the logic for a program that outputs every number from 1 to 20, along with
its value doubled and tripled.

You might also like