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

Algorithm and Programming: Module 2: Introduction To Decision Structure

The document introduces decision structures in programming, which use conditions to determine the next operations. It discusses the different types of decision structures: if, else, and else if. If a decision structure contains another decision structure, it is called nested. The document provides an assignment asking the reader to write a program that prompts a user to create two usernames and passwords, then log in by entering a matching username and password. If either is incorrect, an error message should display.

Uploaded by

Reishou
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)
39 views

Algorithm and Programming: Module 2: Introduction To Decision Structure

The document introduces decision structures in programming, which use conditions to determine the next operations. It discusses the different types of decision structures: if, else, and else if. If a decision structure contains another decision structure, it is called nested. The document provides an assignment asking the reader to write a program that prompts a user to create two usernames and passwords, then log in by entering a matching username and password. If either is incorrect, an error message should display.

Uploaded by

Reishou
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/ 3

ALGORITHM AND PROGRAMMING : MODULE 2

Introduction to Decision Structure

A. Concept

A decision structure, also called branching operation, is a condition where the program
needs to fulfill a certain condition to run an operation(s). Decision structures will always
use either TRUE or FALSE to determine the next operation in a program. Take the
following program for example :

The program asks for a number between 1 and 5, and then a decision structure is
implemented to validate the input.

Another important thing to note is that a decision structure will always consist of one or
more block of statements.
B. If, Else, and Else If

There are 3 kinds of branching operations : If, Else, and Else If.

- IF : If is inclusive, meaning that only and IF ONLY the stated condition is fulfilled, will
the program be able to run the block of statement .
- ELSE : Else is exclusive, meaning that only if prior conditions are not fulfilled, will the
program be able to run the block of statement.
- ELSE IF : Else-if is inclusive-exclusive, meaning that only if prior conditions are not
fulfilled AND the stated condition is fulfilled will the program be able to run the
block of statement.

C. Nested Decision Structure


If a decision structure contains another decision structure, then that decision structure
is called a Nested Decision Structure.
D. Assignment

1. Write a program that prompts the user to enter 2 different username, along with a
password for each name.
2. The program then should ask the user to log in using one of the two usernames.
Assuming the wrong username is entered, the program should output an error
message.
3. The then user must input the correct password for the username. Assuming the
wrong password is entered, the program should output an error message.
4. If the username and password matched, the program should tell the user they have
successfully logged into the system.

~ That’s all, folks. Good luck! ~

You might also like