|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
How do you call repeat/recursive in C#?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
The Project Keeper
|
I've used other languages and i just used.
Repeat (<number of times>) { ; } But in C# i can't seam to find this function...
__________________
|
|||||||||||||
|
|
|
|
#2 (permalink) | ||||||||||||
|
Intel Overclocker
|
for(int i=start; i<end; i++)
__________________{ }
|
||||||||||||
|
|
|
|
#3 (permalink) | ||||||||||||||
|
Turing Test is Overrated
|
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:
|
||||||||||||||
|
|
|
|
#4 (permalink) | ||||||||||||
|
Intel Overclocker
|
I know its not recursive but I believe that is what he wanted judging from his example.
__________________
|
||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||||
|
Turing Test is Overrated
|
Quote:
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:
|
|||||||||||||||
|
|
|
|
#6 (permalink) | ||||||||||||
|
Intel Overclocker
|
My bad
__________________![]()
|
||||||||||||
|
|
|
|
#7 (permalink) | ||||||||||||||
|
The Project Keeper
|
Can you give me a more in depth explanation?
Quote:
__________________
Last edited by Licht : 12-14-07 at 09:20 PM. |
||||||||||||||
|
|
|
|
#8 (permalink) | |||||||||||||||
|
Programmer
Join Date: Oct 2007
Location: Toronto, Ontario, canada
Posts: 159
Rep: 15
![]() Unique Rep: 14
Trader Rating: 0
|
Quote:
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
}
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();
}
}
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
__________________
Quote:
CPU-Z Validation
Last edited by Polska : 12-16-07 at 08:41 PM. |
|||||||||||||||
|
|
|
|
|
#9 (permalink) | ||||||||||||||
|
The Project Keeper
|
Quote:
Code:
for(int i=0; i<6; i++){
//do something
}
Code:
for(first argument; 2nd argument; 3rd argument)
__________________
|
||||||||||||||
|
|
|
|
#10 (permalink) | ||||||||||||||
|
Programmer
Join Date: Oct 2007
Location: Toronto, Ontario, canada
Posts: 159
Rep: 15
![]() Unique Rep: 14
Trader Rating: 0
|
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;
}
You could however write Code:
for (int i = 0; i < 6; ) {
Console.WriteLine("hi");
i++;
}
Code:
int i = 0;
for (; i < 6; ) {
Console.WriteLine("hi");
i++;
}
Code:
for (int i = 0; i < 6; i++) {
Console.WriteLine("hi");
}
__________________
Quote:
CPU-Z Validation
Last edited by Polska : 12-16-07 at 09:05 PM. |
||||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|