473,387 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

for(x = 0; x < 9; x++) when is x incremented?

Why in the printout of the following code s, t, and u only go up
to 9 but w and x 10? I would think they would at least go up to
the same number, be it 9 or 10.

The last line of the printout is:

column 9 row 9 u 9 v 0 w 10 x 10 y 1 z 48652
-----------------------------------------
for(s = 0; s < 9; s++)
for(t = 0; t < 9; t++)
for(u = 0; u < 9; u++)
{
if(v = Cell[s][t].GetElement(u) != 0)
for(w = 0; w < 9; w++)
{
if(w != t)
{
for(x = 0; x < 9; x++)
{
if(y = Cell[s][w].GetElement(x) != 0)
if(v >= y)
if( v == y)
{
z++;
}
}
}
}
cout << "column " << s+1 << " row " << t+1 << \\
" u " << u+1 << " v " << v << " w " << w+1 << " x " << x+1 \\
<< " y " << y << " z " << z << '\n';
}
Oct 16 '05 #1
7 2595
"John Smith" <js****@company.com> wrote in message
news:VE******************@twister.southeast.rr.com
Why in the printout of the following code s, t, and u only go up
to 9 but w and x 10? I would think they would at least go up to
the same number, be it 9 or 10.


Incrementation takes place after the body of the for() loop is executed. In
your case, the printout occurs after the body of the w and x for loops but
inside the body of the s, t and u loops. That explains the difference.

--
John Carson

Oct 16 '05 #2
The basic "unrolled" (missused, i know) form of a for-loop is:

for( statement; conditional; operation )
{
body;
}

becomes

statement;
while( conditional )
{
body;
operation;
}

and can, in fact, replace all while-loops (but for clarity, while-loops
are still viable)

Oct 16 '05 #3
and you should see any 10s if the condition is "x<9".
The reason is simple - when outputting he sometime print out x+1 and
sometie just 'v'...

None of the variables reaches 10....

Oct 16 '05 #4
Actualy, none of the variables reaches 9, because conditions in all
cases are "x<9", when variable reaches 9 - loop body isn't executed
anymore.
gu*****@gmail.com raše:
and you should see any 10s if the condition is "x<9".
The reason is simple - when outputting he sometime print out x+1 and
sometie just 'v'...

None of the variables reaches 10....


Oct 16 '05 #5
you are wrong.
see that when the condition of the loop is evaluated (x<9) and the body
than skipped, x is already 9! otherwise the body of the loop will be
executed.

when you have something like this:
for (int i=0; i<9; i++) {
/// bla.... some statements
}
cout << i;
the output will always (if the loop was not ended abruptly) be '9'.

Oct 16 '05 #6
I'm sorry, I think I misunderstood you.
I guess you meant '9' is never PRINTED - but you wrote "none of the
variables reaches 9".
But also this is not accurate, because w does reaches 9 in before the
cout command is reached.

Oct 16 '05 #7
gu*****@gmail.com wrote:
you are wrong.
see that when the condition of the loop is evaluated (x<9) and the body
than skipped, x is already 9! otherwise the body of the loop will be
executed.

when you have something like this:
for (int i=0; i<9; i++) {
/// bla.... some statements
}
cout << i;
the output will always (if the loop was not ended abruptly) be '9'.


Please quote the messages in your replies. Use the 'Reply' in the 'More
options' link if you are using the google-groups interface.

And, in
for(int i.....) { }
the scope of 'i' is restricted to within the for loop, it is not visible
outside. :-)

Cheers,
Vimal.
--
"If you would be a real seeker after truth, it is necessary that at
least once in your life you doubt, as far as possible, all things."
-- Rene Descartes
Oct 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniele Varrazzo | last post by:
If you need a container to look into, there is the sets module that provides a couple of them. If you need a sorted list, there is the bisect module. But i don't think it fits your need for a...
33
by: Philip Herlihy | last post by:
I'm creating a common navigation bar of text "buttons" using CSS. On each page, I want the corresponding button to be "inert" (no hover, etc) as a visual clue to where you are. I thought I'd...
15
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width:...
4
by: simon_s_li | last post by:
Hi, Does anyone know if there is an event that gets fired off when I select text in a cell of a table in HTML???? I know theres a onselect event but that does not work. I need this so I can...
4
by: Michael Brown | last post by:
I would like to know if .NET has some sort of event that I can write a method for or something similar for when an application of my choosing starts.
2
by: I appreciate your help.... anony | last post by:
Hi, does anyone know whether it is possible to have a holding page for when an application domain dies and give the "503" error, we would like to replace that error a holding page. Can some one...
0
by: **Developer** | last post by:
Anyone know a good reference for when Events occur? I'm thinking of Load, HandleCreated, Enter, Resize(first time), Print(first time),... and I don't know what else might be run on control (or...
6
by: year1943 | last post by:
For template <typename Tclass My ; I can define partial spec-ns somewhat like template <typename Tclass My<T*; or template <typename Tclass My<Another<T ; And full spec-n, say template <class...
4
by: db2dbdba | last post by:
Hi All, How can I check for when a db2stop command is last issued? Or when a db2 force applications all command is last issued? Thanks in advance R
2
by: Shahid | last post by:
Hi, I am parsing an .HTML file that contains following example code: <div> <p class="html_preformatted" awml:style="HTML Preformatted" dir="ltr" style="text-align:left"><span...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.