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

Computer Programming Lab # 4

The document outlines Lab 4 objectives focused on iteration and jump statements in programming. It includes tasks such as rewriting a calculator program using a switch statement, creating a while loop for user input with specific conditions, calculating a factorial using a for loop, and implementing a do-while loop for password validation. These tasks aim to enhance understanding of control flow in programming.

Uploaded by

afzal2126131
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)
0 views

Computer Programming Lab # 4

The document outlines Lab 4 objectives focused on iteration and jump statements in programming. It includes tasks such as rewriting a calculator program using a switch statement, creating a while loop for user input with specific conditions, calculating a factorial using a for loop, and implementing a do-while loop for password validation. These tasks aim to enhance understanding of control flow in programming.

Uploaded by

afzal2126131
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/ 1

Lab 4: Iteration Statements and Jump Statements

Objectives:
To understand the programming using iteration statements like while, do-while and for Loop and
jump statements like continue, break, return and go to.

Tasks:

1. Rewrite the calculator program made in previous lab, this time use switch statement instead
of else if.

2. Write a program using a while loop that asks the user to enter numbers continuously. The
program should do the following:
• If the user enters a negative number, ignore it using the continue statement and move
to the next input.
• If the user enters 0, stop the loop using the break statement.
• For all positive numbers, add them to a running total (sum).
• Finally, display the sum of all valid positive numbers entered by the user.

3. Write a program that uses for loop to find the factorial of a number entered by the user.

4. Write a program using a do-while loop that keeps asking the user to enter a password
until the correct password is entered. The correct password is "1234". After the correct
password is entered, display a welcome message and stop the program.

You might also like