# Loop Loop...

Printable View

• 05-25-2006
peter_hii
Loop Loop...
hi everyone,

can someone give me some hints on how to loop the number from 1 to 23 and after that start from 1 - 23 again and start over again..

thank you..
• 05-25-2006
prog-bman
psuedo
Code:

int val = 1

loop{
//do stuff here
if val = 23{
val = 0
}
val = val + 1
}

• 05-25-2006
peter_hii
hi, i dont understand ur code as i am newbie of c++..

my aim is to produce the day of the physical cycle for biorhythm.

physical day has 23 per cycle...

hope you understand
• 05-25-2006
prog-bman
That was psuedo code. Meaning it wasn't language specific. This is a very simple logic problem and I basically just handed the answer to you so I really don't see the problem.
• 05-25-2006
peter_hii
can other person help me about this..
thnx anyway...
• 05-25-2006
laserlight
Quote:

can other person help me about this..
What part of prog-bman's pseudocode do you have problems understanding?
• 05-25-2006
prog-bman
What do you want someone to do your work for you?
I am sorry you can't figure out such a simple problem. Obviously my efforts were horrible and you being the genius you are, my feeble efforts are too simple for you to understand so please someone who is more intelligent than I help peter with his ultra difficult logic problem.

C++ Code
Code:

#include <iostream>

int main()
{
//This will loop through 1-23 10 times
//I am suprised I know how to do this
int iters = 0;
for(int i = 1; iters < 10; i++){
std::cout<<i<<" ";
if(i == 23){
i = 0;
iters++;
std::cout<<std::endl;
}
}
std::cin.get();
return 0;
}

^Is me being too nice but whatever
• 05-25-2006
peter_hii
cool.. ...............
• 05-25-2006
laserlight
Quote:

Is me being to nice but whatever
Sorry, prog-bman, your solution is wrong. The specification does not allow for printing the numbers to screen, and requires an infinite loop.

A correct solution would be:
Code:

int main()
{
for (;;) for (int i = 1; i <= 23; ++i);
}

• 05-25-2006
prog-bman
I wasn't going to write his code for him just give a general idea ;)
• 05-25-2006
laserlight
Quote:

I wasn't going to write his code for him just give a general idea
Well, now I can claim to be 'nicer' than you :p
• 05-25-2006
prog-bman
You sure are :D
• 05-25-2006
twomers
Hey, laserlight, check out this link!
• 05-25-2006
k1ll3r
Quote:

Hey, laserlight, check out this link!
lol :p
• 05-25-2006
sean
I see you've clicked this link before!

Closed.