English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

a) How many times does the following loop iterate?

b) What is the output displayed on screen?

int x = 8;

while (x < 12)
++x ;
Console.Write(x);

2007-03-23 08:21:05 · 4 answers · asked by S.F.Giants 1 in Computers & Internet Programming & Design

4 answers

The loop iterate 4 times.
Output is 12.

if there where { }braces after the while statements and the following code inside
{
++X;
Console.Write(X);
}
You would have gotten different output.

Since you are "Stuck" on this question I would recommend reading a good C++ book.

2007-03-23 08:27:59 · answer #1 · answered by yairs2000 3 · 1 0

x starts a 8 and the loop runs while x < 12. The output is:

9
10
11

2007-03-23 15:24:12 · answer #2 · answered by Linux OS 7 · 0 0

They key to understanding this is to know that the "while loop" doesn't execute when x=12. Because with a while statement the expression is evaluated first.

Some other loops will execute first, and then check the expression

4 times, 12 as the output

2007-03-23 15:39:01 · answer #3 · answered by SoulRebel79 4 · 0 0

while (x < 12)
{
console.write(x)
++x ;
}

I would open up my compiler, but I'm a little lazy. This code should answer your question though. I'm pretty sure it's just 4.

2007-03-23 15:26:02 · answer #4 · answered by ihateyourgutsandiwantyoutodie 1 · 0 0

fedest.com, questions and answers