Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
how do i solve this loop
Author Message
hpdudette

Posted: Thu May 22, 2003 6:57 pm   Post subject: how do i solve this loop

this is the problem:
write a program containing an infinite loop which out puts a series of integers starting at 5 and going up by 5

kythoon

Posted: Thu May 22, 2003 7:01 pm   Post subject: (No subject)

 code: var number : int := 5 put number loop     number := number + 5     put number end loop

i think this is what u want
Catalyst

Posted: Thu May 22, 2003 7:02 pm   Post subject: (No subject)

not gonna solve for u but heres a hint, use a loop
its REALLY simple
5 lines max

note: kythoon posted while i was posting
hpdudette

Posted: Thu May 22, 2003 7:02 pm   Post subject: (No subject)

thank you soooooo much
netninja

Posted: Mon Feb 16, 2004 7:55 am   Post subject: (No subject)

Would it not be easier to make it count 'by '5's instead of +5??? Its not even sarcasm, i'd like to know. If the numbers start getting big, will the program count faster 'by' numbers, or + the numbers??
Tony

Posted: Mon Feb 16, 2004 8:57 am   Post subject: (No subject)

what do you mean?

and the answer is no
Tony's programming blog. DWITE - a programming contest.
Cervantes

Posted: Mon Feb 16, 2004 3:45 pm   Post subject: (No subject)

Well I think you learned a bit from my tutorial unfortunately, I think you''re getting for loops and loops confused.

The 'by 5' you are getting from a for loop when you do something like this

 code: for counter : 1 .. 100 by 5 %blah blah blah end for

That would work, except you can't use for loops in this problem because it asks to repeat an infinate number of times.

Loops = go on forever until the exit when statement is true
for loops = repeat a defined number of times. (can't set it to be 1 .. infinity)
netninja

Posted: Tue Feb 17, 2004 6:57 pm   Post subject: (No subject)

Yes, that was my question i think, if it was possible to do an infinite loop with the 'by', but i soon realized i had to do the num:=num+5 method. I already understand that. But thanks anyway.

netninja

Posted: Wed Feb 18, 2004 4:08 pm   Post subject: (No subject)

How do you make a loop that generates random integers. My code isnt good at all. I tried doing a for loop, like 1..5, (so i generate 5 random numbers) and randint, but my code is all wrong, 0 % accurate. Can someone help me with that?
Cervantes

Posted: Wed Feb 18, 2004 4:20 pm   Post subject: (No subject)

 code: var randnum : int loop    randnum := Rand.Int (lownum, highnum)  %could also do it like this:   %randint (randnum, lownum, highnum)    put randnum end loop

or if you want to use a for loop

 code: var randnum : int for i : low .. high   randnum := Rand.Int (lownum, highnum)   put randnum end for
netninja

Posted: Wed Feb 18, 2004 8:44 pm   Post subject: (No subject)

But i would like to make it give 5 random integers. I already know how to put 1 AHHHHhhhhHHHH, nevermind, i just noticed something. Thanks alot Cervantes. Sorry for my stupidity. heh, so that code wouldnt work with randint? Only Rand.Int. And i just realized why it fits into this particular code.

Thanks again
TheZsterBunny

Posted: Thu Feb 19, 2004 8:21 am   Post subject: This may be too late but,

This is something you could use

 code: var low := 1 var high := 5 var rhandom : array low..high of int for randemnity: low..high rhandom(randemnity) := Rand.Int(1,5) end for

That would work quite well, but arrays take up a great deal of space.

-z0rQ
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 12 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: