473,698 Members | 2,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hierarchy of nested "for" loops

14 New Member
Hello

I have three "for" loops, two nested into the outer one and they depend on each other, like this:

for (x=1; x<100; x++)
{
....
for (i=1; i<10; i++)
{....}
for (j=1; j<10; j++)
{...}
...
}

In the i loop we obtain a result that must be introduced in the j loop. I thought that it would do firstly the loop for i and then the loop for j, but it seems like if it were doing both loops at the same time, because when we cancell the j loop the result for the i one is correct, but with both working simoultaneously the result for i is perturbed by the second loop. Am I correct?

Thak you very much for your time and for your help!
Apr 30 '07 #1
4 1714
r035198x
13,262 MVP
Hello

I have three "for" loops, two nested into the outer one and they depend on each other, like this:

for (x=1; x<100; x++)
{
....
for (i=1; i<10; i++)
{....}
for (j=1; j<10; j++)
{...}
...
}

In the i loop we obtain a result that must be introduced in the j loop. I thought that it would do firstly the loop for i and then the loop for j, but it seems like if it were doing both loops at the same time, because when we cancell the j loop the result for the i one is correct, but with both working simoultaneously the result for i is perturbed by the second loop. Am I correct?

Thak you very much for your time and for your help!
The braces {} should tell you how your loops will behave.
Apr 30 '07 #2
MDR
14 New Member
The braces {} should tell you how your loops will behave.
ok, thanks but this doesn'tanswer my question.
My question is, which loop does it run before, "i" or "j", or they run simoultaneousll y? because they are at the same level within de "x" loop.
Apr 30 '07 #3
ilikepython
844 Recognized Expert Contributor
ok, thanks but this doesn'tanswer my question.
My question is, which loop does it run before, "i" or "j", or they run simoultaneousll y? because they are at the same level within de "x" loop.
It runs whichever comes first. A for runs everything within its braces so it won't go to the second for loop until the first is finished.
Apr 30 '07 #4
r035198x
13,262 MVP
ok, thanks but this doesn'tanswer my question.
My question is, which loop does it run before, "i" or "j", or they run simoultaneousll y? because they are at the same level within de "x" loop.
Think about the answer I gave you again. Maybe it really does answer your question ...
Apr 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

23
3570
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else: print "Empty list" which was supposed to be:
15
1549
by: adomas.paltanavicius | last post by:
Hi there, I am quite new to Python, and have a straight & simple question. In C, there is for (init; cond; advance). We all know that. In Python there are two ways to loop over i=A..B (numerical.): 1) i = A while i<B: ...do something... i+=STEP 2) for i in range(A, B, STEP):
9
162535
by: adam | last post by:
hello Does exist in SQL language "for" loop ? If yes, what syntax does it has ? best wishes Adam
12
2104
by: Robbie Hatley | last post by:
I'm getting a bizarre error with this code: ... case WM_COMMAND: { switch (LOWORD(wParam)) // switch (control ID) { ... case IDC_RAIN_ENABLE_SIMPLE: {
5
1867
by: Fabian Vilers | last post by:
Hi again... I'm wondering what could be better in terms of performance between: var my_array = new Array(); // populate array for (index in my_array) { // do something with my_array
10
1656
by: s.lipnevich | last post by:
Hi All, I apologize if this was brought up before, I couldn't find any "prior art" :-). On more than one occasion, I found myself wanting to use a "conditional loop" like this (with "Invalid syntax" error, of course): for i in c if <test>: print i*2
34
2674
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include <limits.h> #include <stdlib.h> int main(void) {
1
1608
by: Ralgoth | last post by:
using Flash, I'm sending a bunch of variables to my php script that have ordered names. What I want is to use a "for" loop to identify each variable. This is how I would do it in Flash but don't know how to do it in php... for(i=0; i<3; i++){ this = i; } // the above code would be identical to typing the following... Item0 = 0; Item1 = 1;
2
2072
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.