0% found this document useful (0 votes)
9 views10 pages

While-Loop-4

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)
9 views10 pages

While-Loop-4

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/ 10

While Loop

Definition
• entry-controlled
• a condition is assessed before processing the loop’s body
• a loop’s body will be executed if and only if a condition is met
Use
• used to repeatedly run a block of code up until a predetermined condition is
satisfied
Importance
• in order to create a short code block to do specific code statement/s repeatedly
until a certain condition is met for the program to stop the loop
Illustration
How while() loops function:
• The while loop evaluates the condition.
• If condition is true, statements inside the body of the while loop are executed.
Then, condition is re-evaluated.
• The process goes on until condition is evaluated to be false.
• If condition is false, the loop terminates.
How while() loops function: (cont’d)
Suppose we are going to use the while loop to output numbers 1 to num, the process would go
on like this:
Syntax

• Test Expression: We must test the condition in this expression. If the condition is true,
we will run the loop’s body and proceed to the update expression; otherwise, we will
leave the loop.
• Update Expression: After executing the loop body this expression
increments/decrements the loop variable by some value.
Example
Do you have
any
questions?

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy