While and Do-While Loops [PDF]

Loops. • Within a method, we can alter the flow of control using either conditionals or loops. • The loop statements

118 downloads 10 Views 162KB Size

Recommend Stories


FUNctions, Loops, and Expressions
Just as there is no loss of basic energy in the universe, so no thought or action is without its effects,

לולאות while, do while
Every block of stone has a statue inside it and it is the task of the sculptor to discover it. Mich

Hard Loops, Soft Loops, and High Density Effective Field Theory
The greatest of richness is the richness of the soul. Prophet Muhammad (Peace be upon him)

chromosome loops
Don't watch the clock, do what it does. Keep Going. Sam Levenson

Cosmic Loops
The greatest of richness is the richness of the soul. Prophet Muhammad (Peace be upon him)

(Induction) Loops
Courage doesn't always roar. Sometimes courage is the quiet voice at the end of the day saying, "I will

Loops Continued, preventing and debugging errors, year 2.pdf
Don't count the days, make the days count. Muhammad Ali

stress and strain while driving
The only limits you see are the ones you impose on yourself. Dr. Wayne Dyer

Closing the food loops
I cannot do all the good that the world needs, but the world needs all the good that I can do. Jana

For Loops in Python
Before you speak, let your words pass through three gates: Is it true? Is it necessary? Is it kind?

Idea Transcript


While and Do-While Loops 15-110 Summer 2010 Margaret Reid-Miller

Loops •  Within a method, we can alter the flow of control using either conditionals or loops. •  The loop statements while, do-while, and for allow us execute a statement(s) over and over. •  Like a conditional, a loop is controlled by a boolean expression that determines how many times the statement is executed. E.g., You may want to calculate the interest paid on a mortgage for each year of the loan term.

Summer 2010

15-110 (Reid-Miller)

The while statement •  The form of the while statement is while () •  If boolean_expression evaluates to true, then statement is executed. •  Then, the boolean_expression is evaluated again. If it evaluates to true, statement is executed again. •  This repetition continues until the boolean_expression evaluates to false. How is the while loop different from the if statement? Summer 2010

15-110 (Reid-Miller)

The if Flowchart

boolean_expression true statement (body of loop)

Summer 2010

15-110 (Reid-Miller)

false

The while Flowchart

boolean_expression true statement (body of loop)

Summer 2010

15-110 (Reid-Miller)

false

n=5

A while Example

i

i

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.