0% found this document useful (0 votes)
2 views8 pages

Understanding Control Structures in Coding

The document outlines control structures in programming, focusing on if statements, if-else statements, loops, and nested loops. It includes examples and pseudocode for tasks such as determining the value of 'y' based on whether 'x' is odd or even, and summing even numbers within a specified range. The session aims to help users understand and effectively utilize these control structures in their scripts.

Uploaded by

KwongYew Ngu
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)
2 views8 pages

Understanding Control Structures in Coding

The document outlines control structures in programming, focusing on if statements, if-else statements, loops, and nested loops. It includes examples and pseudocode for tasks such as determining the value of 'y' based on whether 'x' is odd or even, and summing even numbers within a specified range. The session aims to help users understand and effectively utilize these control structures in their scripts.

Uploaded by

KwongYew Ngu
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

Control structures

Session outcomes:

To understand and use


If statement
If-else statement
Loop
Nested loop
Repeat, break, next

If
If else, continued

Try
● Write a script that sets the value of y depending
on the value of x
− If x is an odd number, y is x times 10
− If x is an even number, y is x times 20
odd number
X 100
* -

/
L
Pseudocode if(x 0)[ if (x/ % 2 1)[
%% 2 ! or ==
=

⑧ define X
x * 10
ye
-

② check if X is odd or even

③ if * is odd ,
set
y
= x +
10
Zelse[
if not Set y x 20
ye x * 20
+
-
=
,

3
* =
200
number
even

100
XX-100 X
- =
50 & ne remainder
2

odd
if (X %%. 2 ! =
0)[ number

X e x -
+
1

3 else [ ~

Xe-X-1

Y ? -> Xe-100-1

x1 99

opposite the XI.. 2 == 0 statement


X1- 10
X8
=

Bota I
=

if (x20) [ X

* %% 2 ! =
0
X < x+ 1 -

3 if (x<100)[ X

x + -
x +
2
#

3 else [ v

Xe x 3
+

3
x =
13
C
T/E
Both TRVE then

Y
if (statement 1) E ,

only can
proceed
T/E with do action la
if (Statement (a) [ If either one FALLE
,

·else
do
· .

action I

Jesse [
do action 2

3
Loop

Loop
Loop

Try
● Write a script that Csum all even numbersSin the
range of 1 and 100. * - 1 100
:

Sum &- O
Pseudocode
⑧ define X for (i in x)[
② If (i%2 = =
0) [
③ Sum & Sum+

3
Nested Loop

While
Try
● Write a script that sum all even numbers in the
range of 1 and 100 until the sum exceeds 50.

Control structures
Session outcomes:

To understand and use


If statement
If-else statement
Loop
Nested loop
Repeat, break, next

You might also like