Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 12-10-07   #1 (permalink)
The Project Keeper
 
Licht's Avatar
 
amd ati

Join Date: Mar 2007
Location: Bel Air
Posts: 9,550
Blog Entries: 3

Rep: 278 Licht is a proven memberLicht is a proven memberLicht is a proven member
Unique Rep: 184
Folding Team Rank: 880
Trader Rating: 0
Default How do you call repeat/recursive in C#?

I've used other languages and i just used.

Repeat (<number of times>)
{
;
}

But in C# i can't seam to find this function...

System: Uzicht #3
CPU
Athlon X2 5200+ Windsor
Motherboard
Gigabyte 790X AM2+
Memory
6GB Kingston DDR2 667MHZ
Graphics Card
Saphire HD 3870
Hard Drive
2x WD 160GB 7,200RPM RAID0
Sound Card
X-Fi Extreme Gamer Fatality Professional
Power Supply
OCZ Game-X-Stream 700w
Case
NZXT Black Steel
CPU cooling
AMD Stock Cooling
GPU cooling
Stock Saphire 3870 Cooling
OS
Windows Vista Home Premium x64 SP1
Monitor
Samsung SyncMaster 19"Wide
Licht is offline I fold for Overclock.net Overclocked Account Licht's Gallery   Reply With Quote
Old 12-10-07   #2 (permalink)
Intel Overclocker
 
dante020's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Novi, MI
Posts: 198

Rep: 34 dante020 is acknowledged by some
Unique Rep: 23
Folding Team Rank: 107
Trader Rating: 4
Default

for(int i=start; i<end; i++)
{

}
__________________
System: The System
CPU
Q6600 @ 3.2Ghz - 356FSB
Motherboard
Asus P5Q Pro
Memory
OCZ Platinum Rev. 2 4x1GB
Graphics Card
EVGA 8800GT 512MB
Hard Drive
WD Raptor 150GB x 2
Sound Card
Creative X-Fi XtremeGamer
Power Supply
Corsair CMPSU-620HX 620W
Case
Antec P180B
CPU cooling
Scythe Ninja SCNJ-1000
OS
Windows Vista Ultimate x64
Monitor
Samsung 226BW 22" LCD
dante020 is offline I fold for Overclock.net   Reply With Quote
Old 12-10-07   #3 (permalink)
Turing Test is Overrated
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 24,338

Rep: 2835 DuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legend
Unique Rep: 1306
Folding Team Rank: 962
Trader Rating: 34
Default

That's not recursive... that is just a simple "For Loop"

Recursive is:
Code:
Repeat (Exit Criteria)
{
    Repeart (Exit Criteria);
}
__________________
WANTED: Socket M Core/Core 2 CPU, SUGO-02 Black, quality 802.11b/g PCI Card
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it will work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single/Non-Modular Rail PSUs are NOT better than Multi-Rail/Modular

Quote:
catmmm: no wifi? gay
e_dogg: I use both wired and wireless in my house. Does that make me bi?

System: My "DF-DIE" Replacement
CPU
Q6600 (3.7GHz)
Motherboard
Asus P5E X38 (MF1208 BIOS)
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
8800GT (729/1836/2088)
Hard Drive
PERC 5/i: 3xRAID0 Raptor 74GB + 7200.10 250GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
MCW60 + Iandh HS + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is offline I fold for Overclock.net Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 12-10-07   #4 (permalink)
Intel Overclocker
 
dante020's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Novi, MI
Posts: 198

Rep: 34 dante020 is acknowledged by some
Unique Rep: 23
Folding Team Rank: 107
Trader Rating: 4
Default

I know its not recursive but I believe that is what he wanted judging from his example.
__________________
System: The System
CPU
Q6600 @ 3.2Ghz - 356FSB
Motherboard
Asus P5Q Pro
Memory
OCZ Platinum Rev. 2 4x1GB
Graphics Card
EVGA 8800GT 512MB
Hard Drive
WD Raptor 150GB x 2
Sound Card
Creative X-Fi XtremeGamer
Power Supply
Corsair CMPSU-620HX 620W
Case
Antec P180B
CPU cooling
Scythe Ninja SCNJ-1000
OS
Windows Vista Ultimate x64
Monitor
Samsung 226BW 22" LCD
dante020 is offline I fold for Overclock.net   Reply With Quote
Old 12-10-07   #5 (permalink)
Turing Test is Overrated
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 24,338

Rep: 2835 DuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legend
Unique Rep: 1306
Folding Team Rank: 962
Trader Rating: 34
Default

Quote:
Originally Posted by dante020 View Post
I know its not recursive but I believe that is what he wanted judging from his example.
Wasn't directed at you... I was referring to the title.

Licht... For, Select/Case, and While looping is pretty standard in all languages.
__________________
WANTED: Socket M Core/Core 2 CPU, SUGO-02 Black, quality 802.11b/g PCI Card
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it will work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single/Non-Modular Rail PSUs are NOT better than Multi-Rail/Modular

Quote:
catmmm: no wifi? gay
e_dogg: I use both wired and wireless in my house. Does that make me bi?

System: My "DF-DIE" Replacement
CPU
Q6600 (3.7GHz)
Motherboard
Asus P5E X38 (MF1208 BIOS)
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
8800GT (729/1836/2088)
Hard Drive
PERC 5/i: 3xRAID0 Raptor 74GB + 7200.10 250GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
MCW60 + Iandh HS + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is offline I fold for Overclock.net Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 12-10-07   #6 (permalink)
Intel Overclocker
 
dante020's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Novi, MI
Posts: 198

Rep: 34 dante020 is acknowledged by some
Unique Rep: 23
Folding Team Rank: 107
Trader Rating: 4
Default

My bad
__________________
System: The System
CPU
Q6600 @ 3.2Ghz - 356FSB
Motherboard
Asus P5Q Pro
Memory
OCZ Platinum Rev. 2 4x1GB
Graphics Card
EVGA 8800GT 512MB
Hard Drive
WD Raptor 150GB x 2
Sound Card
Creative X-Fi XtremeGamer
Power Supply
Corsair CMPSU-620HX 620W
Case
Antec P180B
CPU cooling
Scythe Ninja SCNJ-1000
OS
Windows Vista Ultimate x64
Monitor
Samsung 226BW 22" LCD
dante020 is offline I fold for Overclock.net   Reply With Quote
Old 12-14-07   #7 (permalink)
The Project Keeper
 
Licht's Avatar
 
amd ati

Join Date: Mar 2007
Location: Bel Air
Posts: 9,550
Blog Entries: 3

Rep: 278 Licht is a proven memberLicht is a proven memberLicht is a proven member
Unique Rep: 184
Folding Team Rank: 880
Trader Rating: 0
Default

Quote:
Originally Posted by dante020 View Post
for(int i=start; i<end; i++)
{

}
Can you give me a more in depth explanation?

Quote:
That's not recursive... that is just a simple "For Loop"

Recursive is:
That is C# right? Giving me errors, of course i don't fully understand the way to use either (C# noob.)

System: Uzicht #3
CPU
Athlon X2 5200+ Windsor
Motherboard
Gigabyte 790X AM2+
Memory
6GB Kingston DDR2 667MHZ
Graphics Card
Saphire HD 3870
Hard Drive
2x WD 160GB 7,200RPM RAID0
Sound Card
X-Fi Extreme Gamer Fatality Professional
Power Supply
OCZ Game-X-Stream 700w
Case
NZXT Black Steel
CPU cooling
AMD Stock Cooling
GPU cooling
Stock Saphire 3870 Cooling
OS
Windows Vista Home Premium x64 SP1
Monitor
Samsung SyncMaster 19"Wide

Last edited by Licht : 12-14-07 at 09:20 PM.
Licht is offline I fold for Overclock.net Overclocked Account Licht's Gallery   Reply With Quote
Old 12-16-07   #8 (permalink)
Programmer
 
Polska's Avatar
 
intel nvidia

Join Date: Oct 2007
Location: Toronto, Ontario, canada
Posts: 159

Rep: 15 Polska Unknown
Unique Rep: 14
Trader Rating: 0
Default

Quote:
Originally Posted by Licht View Post
That is C# right? Giving me errors, of course i don't fully understand the way to use either (C# noob.)
More concrete examples.

1)This for loop will run 6 times. First "i" is initialized to 0, then checked against the condition "i<6", if true runs code "do something" then "i" is incremented by 1, and the loop runs over and over until i<6 fails (so when i is 6). So the code inside the for loop would run 6 times in this case.
Code:
for(int i=0; i<6; i++){
    //do something
}
2) Recursion sample, program will use recursion and print all positive numbers less then or equal to 10. Here when the function lessthenorequal(Number) is called, it prints Number, decrements Number by 1, and calls itself with the new decremented value.

It is important to notice that a call to lessthenorequal(Number) does not exit until the call it makes to itself exits (if it makes a call to itself).
Code:
using System;

class Program {
    static void lessthenorequal(int a) {
        if (a >= 0) {
            Console.Write("{0}, ", a);
            a--;
            lessthenorequal(a);
        }
    }

    static void Main() {
        const int Number = 10;

        Console.WriteLine("Number less then or equal to {0}", Number);
        lessthenorequal(Number);

        Console.WriteLine();
    }
}
Lets trace a call to lessthenorequal(2):

Code:
lessthenorequal(2)
  prints 2,
  decrements 2 by 1
  calls lessthenorequal(1)
    prints 1,
    decrements 1 by 1
    calls lessthenorequal(0)
      prints 0,
      decrements 0 by 1
      calls lessthenorequal(-1)
        does nothing
      lessthenorequal(-1) exits
    lessthenorequal(0) exits
  lessthenorequal(1) exits
lessthenorequal(2) exits
I'm not the best teacher but I hope that explains things a tad for you. Other constructs you may want to google and get familiar with are: "while loop", "Do While Loop", "For Each Loop". They all have their uses at different times, sometimes it is suitable to use several depending on your choice.
__________________
Quote:
Originally Posted by roningai
Never,eva go AS5 to mouth....
GPU-Z Validation
CPU-Z Validation

System: Big Polish Sausage
CPU
E6850 3.4Ghz @ 1.4v
Motherboard
Asus P5KC
Memory
Corsair Dual Channel TWINX 4096MB PC6400 DDR2 800
Graphics Card
EVGA 8800 GTS 640MB @ 650/1000
Hard Drive
WD 150Gb Raptor, Seagate 500Gb
Sound Card
Turtle Beach - Montego DDL
Power Supply
Ultra 700W
Case
Ultra Grid ATX Case
CPU cooling
zalman 9700
GPU cooling
stock
OS
Vista Ultimate SP1 (32 bit)
Monitor
Samsung 226BW

Last edited by Polska : 12-16-07 at 08:41 PM.
Polska is offline   Reply With Quote
Old 12-16-07   #9 (permalink)
The Project Keeper
 
Licht's Avatar
 
amd ati

Join Date: Mar 2007
Location: Bel Air
Posts: 9,550
Blog Entries: 3

Rep: 278 Licht is a proven memberLicht is a proven memberLicht is a proven member
Unique Rep: 184
Folding Team Rank: 880
Trader Rating: 0
Default

Quote:
Originally Posted by Polska View Post
More concrete examples.

1)This for loop will run 6 times. First "i" is initialized to 0, then checked against the condition "i<6", if true runs code "do something" then "i" is incremented by 1, and the loop runs over and over until i<6 fails (so when i is 6). So the code inside the for loop would run 6 times in this case.
Code:
for(int i=0; i<6; i++){
    //do something
}
2) Recursion sample, program will use recursion and print all positive numbers less then or equal to 10. Here when the function lessthenorequal(Number) is called, it prints Number, decrements Number by 1, and calls itself with the new decremented value.

It is important to notice that a call to lessthenorequal(Number) does not exit until the call it makes to itself exits (if it makes a call to itself).
Code:
using System;

class Program {
    static void lessthenorequal(int a) {
        if (a >= 0) {
            Console.Write("{0}, ", a);
            a--;
            lessthenorequal(a);
        }
    }

    static void Main() {
        const int Number = 10;

        Console.WriteLine("Number less then or equal to {0}", Number);
        lessthenorequal(Number);

        Console.WriteLine();
    }
}
Lets trace a call to lessthenorequal(2):

Code:
lessthenorequal(2)
  prints 2,
  decrements 2 by 1
  calls lessthenorequal(1)
    prints 1,
    decrements 1 by 1
    calls lessthenorequal(0)
      prints 0,
      decrements 0 by 1
      calls lessthenorequal(-1)
        does nothing
      lessthenorequal(-1) exits
    lessthenorequal(0) exits
  lessthenorequal(1) exits
lessthenorequal(2) exits
I'm not the best teacher but I hope that explains things a tad for you. Other constructs you may want to google and get familiar with are: "while loop", "Do While Loop", "For Each Loop". They all have their uses at different times, sometimes it is suitable to use several depending on your choice.
Code:
for(int i=0; i<6; i++){
    //do something
}
I wanna focus on this, i have a few questions. What exactly is the syntax for this?

Code:
for(first argument; 2nd argument; 3rd argument)
What exactly gos in for each argument? Is it always used to initiate a variable, run a check, then perform a mathematical change to the variable?

System: Uzicht #3
CPU
Athlon X2 5200+ Windsor
Motherboard
Gigabyte 790X AM2+
Memory
6GB Kingston DDR2 667MHZ
Graphics Card
Saphire HD 3870
Hard Drive
2x WD 160GB 7,200RPM RAID0
Sound Card
X-Fi Extreme Gamer Fatality Professional
Power Supply
OCZ Game-X-Stream 700w
Case
NZXT Black Steel
CPU cooling
AMD Stock Cooling
GPU cooling
Stock Saphire 3870 Cooling
OS
Windows Vista Home Premium x64 SP1
Monitor
Samsung SyncMaster 19"Wide
Licht is offline I fold for Overclock.net Overclocked Account Licht's Gallery   Reply With Quote
Old 12-16-07   #10 (permalink)
Programmer
 
Polska's Avatar
 
intel nvidia

Join Date: Oct 2007
Location: Toronto, Ontario, canada
Posts: 159

Rep: 15 Polska Unknown
Unique Rep: 14
Trader Rating: 0
Default

The general Syntax would be:

syntax:
Code:
for (statement1; expression; statement2)
    statement[s]3

curly brackets used to nest several statements
for (statement1; expression; statement2) {
    statement3;
    statement4;
    statement5;
}
statement2 doesn't necessarily have to correlate to statement1, but generally it does. This way you keep the loop structure seperate from whatever you want to loop.

You could however write
Code:
 for (int i = 0; i < 6; ) {
     Console.WriteLine("hi");
     i++;
 }
or even
Code:
int i = 0;
for (; i < 6; ) {
   Console.WriteLine("hi");
   i++;
}
and they are equivalent to;
Code:
for (int i = 0; i < 6; i++) {
     Console.WriteLine("hi");
}
__________________
Quote:
Originally Posted by roningai
Never,eva go AS5 to mouth....
GPU-Z Validation
CPU-Z Validation

System: Big Polish Sausage
CPU
E6850 3.4Ghz @ 1.4v
Motherboard
Asus P5KC
Memory
Corsair Dual Channel TWINX 4096MB PC6400 DDR2 800
Graphics Card
EVGA 8800 GTS 640MB @ 650/1000
Hard Drive
WD 150Gb Raptor, Seagate 500Gb
Sound Card
Turtle Beach - Montego DDL
Power Supply
Ultra 700W
Case
Ultra Grid ATX Case
CPU cooling
zalman 9700
GPU cooling
stock
OS
Vista Ultimate SP1 (32 bit)
Monitor
Samsung 226BW

Last edited by Polska : 12-16-07 at 09:05 PM.
Polska is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 07:59 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.30869 seconds with 8 queries