Author |
Message |
jamonathin
|
Posted: Thu May 05, 2005 8:59 am Post subject: How to Loop? |
|
|
How can you run just a basic loop? What I'm trying to do is make this program (http://www.compsci.ca/v2/viewtopic.php?t=8675) and I can do everything, but loop. Any suggestions? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
rdrake
|
Posted: Thu May 05, 2005 11:10 am Post subject: (No subject) |
|
|
If you're using C, something like
code: | while (1)
{
// code goes here
} | should work.
If you're trying to make a for loop, then
code: | int i;
for (i=0;i<5;i++)
{
// code goes here
} | should work. |
|
|
|
|
|
jamonathin
|
Posted: Thu May 05, 2005 1:19 pm Post subject: (No subject) |
|
|
Im using C++, and so how would I go about exiting the loop though. The type of loop Im looking for is just like the one in turing
Turing: |
loop
exit when . . .
end loop
|
|
|
|
|
|
|
wtd
|
Posted: Thu May 05, 2005 1:40 pm Post subject: (No subject) |
|
|
Well, something like:
c++: | int i;
while (true)
{
std::cin >> i;
if (i == 53)
{
break;
}
} |
|
|
|
|
|
|
jamonathin
|
Posted: Fri May 06, 2005 1:20 pm Post subject: (No subject) |
|
|
sweet, thanks man. |
|
|
|
|
|
MysticVegeta
|
Posted: Mon Jun 20, 2005 8:04 am Post subject: (No subject) |
|
|
I came across a C++ book and another way to infinite loop is ->
code: | for (; ;){
//code here
}
|
I think it works |
|
|
|
|
|
1of42
|
Posted: Mon Jun 20, 2005 7:22 pm Post subject: (No subject) |
|
|
Or, to be cute...
c++: |
#define EVER ;;
for(EVER)
{
}
|
|
|
|
|
|
|
wtd
|
Posted: Tue Jun 21, 2005 2:19 am Post subject: (No subject) |
|
|
Being cute in such languages isn't cute. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
1of42
|
Posted: Tue Jun 21, 2005 11:34 am Post subject: (No subject) |
|
|
Well, you could just go spoil ALL my fun... *pouts* |
|
|
|
|
|
wtd
|
Posted: Tue Jun 21, 2005 12:09 pm Post subject: (No subject) |
|
|
1of42 wrote: Well, you could just go spoil ALL my fun... *pouts*
The problem is that some student will come in here, see that, and consider it the best way to loop. |
|
|
|
|
|
MysticVegeta
|
Posted: Tue Jun 21, 2005 4:05 pm Post subject: (No subject) |
|
|
wtd wrote:
The problem is that some student will come in here, see that, and consider it the best way to loop. ... and his teacher will cut his mark for redundant code, illegal use of vars and not following instructions, and if you have a teacher like ours, dam someone is in deep s**t |
|
|
|
|
|
1of42
|
Posted: Tue Jun 21, 2005 5:58 pm Post subject: (No subject) |
|
|
MysticVegeta wrote: illegal use of vars
s'not a var, just a text substitution |
|
|
|
|
|
Cinjection
|
Posted: Wed Jun 22, 2005 5:51 pm Post subject: (No subject) |
|
|
Programming's an art, NOT a science. This is very debatable, but that's my opinion. If you find a creative or fun way of doing something, you shouldn't be penalised for it. As long as it's not really bad coding style....like goto or something. I ALWAYS make my first for loop var 'c' so i can go:
code: |
for(int c = 0;c <= 100; c++){cout<<"cat"<<endl;} //notice the
//c++......hehe
|
|
|
|
|
|
|
wtd
|
Posted: Wed Jun 22, 2005 5:54 pm Post subject: (No subject) |
|
|
1of42 wrote: MysticVegeta wrote: illegal use of vars
s'not a var, just a text substitution
Which is bad, because it means that the code you're seeing, and the code the compiler is seeing are different. |
|
|
|
|
|
1of42
|
Posted: Wed Jun 22, 2005 9:51 pm Post subject: (No subject) |
|
|
wtd wrote: Which is bad, because it means that the code you're seeing, and the code the compiler is seeing are different.
Never said it wasn't bad, it's just not an illegal use of variables. It's a bad practice, that's all.
And Cinjection - I do that too |
|
|
|
|
|
|