473,739 Members | 2,602 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 1716
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
3576
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
1555
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
162539
by: adam | last post by:
hello Does exist in SQL language "for" loop ? If yes, what syntax does it has ? best wishes Adam
12
2109
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
1871
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
1659
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
2679
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
1612
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
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9266
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
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
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...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
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
4570
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...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.