0% found this document useful (0 votes)
30 views17 pages

Grade 10 - Unit 5 - Program 5

The document provides pseudocode and flowcharts to illustrate while loops with multiple criteria. It shows how to create a program that takes a number input from the user and checks if it is a prime number or not. The program uses a while loop with two conditions - that the counter is less than the number minus 1, and that the prime boolean is true. It iterates through checking if the number is divisible by the counter, and if so sets prime to false. After the loop it outputs whether the number is prime or not based on the prime boolean.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views17 pages

Grade 10 - Unit 5 - Program 5

The document provides pseudocode and flowcharts to illustrate while loops with multiple criteria. It shows how to create a program that takes a number input from the user and checks if it is a prime number or not. The program uses a while loop with two conditions - that the counter is less than the number minus 1, and that the prime boolean is true. It iterates through checking if the number is divisible by the counter, and if so sets prime to false. After the loop it outputs whether the number is prime or not based on the prime boolean.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Chapter 5 (programming

Book)
Iteration
Ms. Naureen Q
Coronavirus
health and safety tips

Wash your Use hand Wear a mask  Don’t touch


hands often  sanitizer  your face 

Cover your sneezes Avoid close Use your own Avoid shaking
and coughs  contact  supplies  hands
3

A conjunction we can use in


the following sentence
✖ I saw an accident _____ I was waiting at the bus
stop.

WHILE
4

Objective

 Illustrate a flowchart and Pseudocode for a while


program.
 Explain with the help of flowchart and pseudocode While
Loop with multiple criteria
5

Create a system that requires output of the


multiples of a given number up to 10 multiples.
Enter a number 10

10
20
30
40
50
60
70
80
90
100
START In Pseudocode the Do is placed after the condition:
WHILE ‘condition’ DO
code to be iterated
Counter  0 LOOP
Multiple  0
But when programming in VB it is placed at the
INPUT beginning: DO WHILE
Number
INT: Counter  0
No INT: Multiple  0
Counter
END
<=10?
INPUT Number
Yes
Multiple  WHILE Counter <= 10 DO
Number * Counter
Multiple Counter * Number
OUTPUT OUTPUT Multiple
Multiple Counter  Counter + 1
Counter 
Counter + 1 Loop
Programming Codes
Dim multiply As Integer
Dim counter As Integer
Console.WriteLine("input num")
multiply = Console.ReadLine
Do While counter <= 10
Console.WriteLine(multiply * counter)
counter = counter + 1
Loop
Console.ReadKey()
8

Objective

 Illustrate a flowchart and Pseudocode for a


while program.
If the condition is not met then the loop will not
run. How will the program continue?

The program will shift to next


line of codes after the Loop to
continue running.
10

WHILE Loops with Multiple Criteria

✖ While Loop can check multiple condition at a time because of this it can
provide an efficient solution.

✖ To have multiple condition a Logical connecting operator ‘AND’ is used.


○ When a condition has AND in it, that means both statement joining
with AND should be true for the program to move on.

In Common language example would be ‘If I had pilot license and a jet I could travel
anywhere anytime’
11

Create a program to take an input from the


user and then check if the number is Prime
or Not

Enter a number: 5
Prime Number

Enter a number: 6
Not a Prime Number
START
Boolean variable can have either Counter  2
a TRUE and FALSE value. It is Num  0 END
used to indicate a condition of a Modulus  0
Prime  True
statement.
INPUT OUTPUT
Number “Prime
Number”
Yes
Counter < Num
No
–1 Prime =
AND True
Prime = True
No
Yes OITPUT
Modulus  Num
Mod Counter “Not a Prime
Number”
Counter  Prime  Yes Modulus
Counter + 1 False =0
END
No
13
IF Prime = True
INT: Num  0
OUTPUT “Number is Prime”
INT: Modulus  0
Else
INT: Counter  2
OUTPUT “Not Prime Number”
BOOLEAN: Prime  True
END IF

INPUT Num

While Counter < Num-1 AND Prime = True DO


Modulus  Num Mod Counter
IF Modulus = 0 THEN
Prime  False
END IF
Counter  Counter + 1
LOOP
14
Dim Num As Integer = 0 If Prime = True Then
Console.WriteLine("Prime Number")
Dim Modulus As Integer = 0 Else
Dim Prime As Boolean = True Console.WriteLine("Not a Prime Number")
End If
Dim Counter As Integer = 2 Console.ReadKey()

Console.WriteLine("Enter a Number")
Num = Console.ReadLine

Do While Counter < Num - 1 And Prime = True


Modulus = Num Mod Counter
If Modulus = 0 Then
Prime = False
End If
Counter = Counter + 1
Loop
15

Objective

 Explain with the help of flowchart and pseudocode While


Loop with multiple criteria
Plenary

 Flowchart and Pseudocode for a while program.

 Flowchart and pseudocode While Loop with multiple


criteria
17
INT: Num  0
INT: Modulus  0
INT: Counter  2
BOOLEAN: Prime  True

INPUT Num

While Counter < Num-1 AND Prime = True DO


Modulus  Num Mod Counter
IF Modulus = 0 THEN
Prime  False
END IF
Counter  Counter + 1
LOOP
IF Prime = True
OUTPUT “Number is Prime”
Else
OUTPUT “Not Prime Number”
END IF

You might also like