Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
nested loops!
Author Message
cutiegirl_14_16

Posted: Sun Mar 02, 2003 4:58 am   Post subject: nested loops!

could somebody help me with nested loops ans for statements... I don't understand for statements, and I need it explained to me in laymans terms.

here's an example of 2 of the programs.

1. Write a program to evaluate xsqaured -ysquared for all combinations of x where x=-2,-1,0,1,2 and y=0,2,4,6,8,10. print out the results in table form.

2. given data which contains the number f children in a family followed by names of those children and en end of file record

3 john susan mark
1 michelle
4 alex david ryan chirs
2 jesse justin
write a program to read the data from a file called childdat.t and print the names of the children in each family. Output the average number of children in the families.

THANX!

Tony

Posted: Sun Mar 02, 2003 11:04 pm   Post subject: (No subject)

loops keep on running over and over until an exit statment is given. In forloops, theres a build in counter that keeps track of how many times the loop was executed and when sertain number is reached, it will terminate.

In nested loops, the inside loop will run for each value of outside loop.

such as
 code: for x:1..3 for y:1..3 put x, " ", y end for end for

this will output
1,1
1,2
1,3
2,1
2,2
etc...

thats because inside forloop (1..3) will execute for each time outter loop is run so there will be a total of 6 outputs (3*3)

This technique is very useful to read/write grids/matrix systems.
Tony's programming blog. DWITE - a programming contest.
azndragon

Posted: Mon Mar 03, 2003 6:17 am   Post subject: (No subject)

For loops really help with probability programs. I had it calculate how many combinations are possible using 12 numbers, and have it calculate how many times certain numbers appeared in certain slots, like how many times the number 1 would be first on the list, etc.
cutiegirl_14_16

Posted: Thu Mar 06, 2003 8:21 pm   Post subject: thanx

thanx 4 the help!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: