<< Chapter < Page Chapter >> Page >

The third clause can contain none, one, or more valid expressions separated by commas.

If there are more than one, they are evaluated in left-to-right order.

When they are evaluated

The expressions in the third clause are evaluated once during each iteration.

However, it is very important to remember that despite the physical placement of the clause in the first line, the expressions in the third clause are notevaluated until after the code in the block has been evaluated.

Typically an update clause

The third clause is typically used to update a counter, but this is not a technical requirement.

This clause can be used for just about any purpose.

However, the counter must be updated somewhere within the block of code or the loop will never terminate.

(Stated differently, something must occur within the block of code to eventually cause the conditional expression to evaluate to false.Otherwise, the loop will never terminate on its own. However, it is possible to execute a return or break within the block to terminate the loop.)

Note the first output value for this program

Because the update in the third clause is not executed until after the code in the block has been executed, the first value displayed by this program is the value zero.

Back to Question 12

Answer 11

E. None of the above

Explanation 11

And the answer is ...

The output produced by this program is:

1 3 5

A simple while loop

This program uses a simple while loop to display the value of a counter, once during each iteration.

Behavior of a while loop

As long as the relational expression in the conditional clause returns true, the block of code immediately following the conditional clause is executed.

When the relational expression returns false, the block of code following the conditional clause is skipped and control passes to the next executablestatement following that block of code.

An entry-condition loop

The while loop is an entry condition loop, meaning that the test is performed once during each iteration before the block of code is executed.

If the first test returns false, the block of code is skipped entirely.

An exit-condition loop

There is another loop, known as a do-while loop, that performs the test after the block of code has been executed once. This guarantees that theblock of code will always be executed at least once.

Just to make things interesting ...

Two statements using the increment operator were placed inside the loop in this program.

Therefore, insofar as the conditional test is concerned, the counter is being incremented by twos. This causes the output to display the sequence 1 3 5.

Nested while loops

The while loop control structure can contain loops nested inside of loops, which leads to some interesting behavior.

Back to Question 11

Answer 10

F. x != 4,5,6

Explanation 10

A multiple-choice structure

This is a form of control structure that is often used to make logical decisions in a multiple-choice sense.

This is a completely general control structure. It can be used with just about any type of data.

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask