Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to Loop?
Index -> Programming, C++ -> C++ Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jamonathin




PostPosted: 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? Smile
Sponsor
Sponsor
Sponsor
sponsor
rdrake




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Fri May 06, 2005 1:20 pm   Post subject: (No subject)

sweet, thanks man. Smile
MysticVegeta




PostPosted: 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




PostPosted: Mon Jun 20, 2005 7:22 pm   Post subject: (No subject)

Or, to be cute...

c++:

#define EVER ;;

for(EVER)
{
}
wtd




PostPosted: Tue Jun 21, 2005 2:19 am   Post subject: (No subject)

Being cute in such languages isn't cute.
Sponsor
Sponsor
Sponsor
sponsor
1of42




PostPosted: Tue Jun 21, 2005 11:34 am   Post subject: (No subject)

Well, you could just go spoil ALL my fun... *pouts* Wink
wtd




PostPosted: Tue Jun 21, 2005 12:09 pm   Post subject: (No subject)

1of42 wrote:
Well, you could just go spoil ALL my fun... *pouts* Wink


The problem is that some student will come in here, see that, and consider it the best way to loop.
MysticVegeta




PostPosted: 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




PostPosted: 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 Rolling Eyes
Cinjection




PostPosted: 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




PostPosted: 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 Rolling Eyes


Which is bad, because it means that the code you're seeing, and the code the compiler is seeing are different.
1of42




PostPosted: 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 Very Happy
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: