473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Re: Reverse Loop?

On Sat, 17 May 2008 16:36:17 -0700, <msnews.microsoft.comwrote:
[...]
I can't seem to get the for (int i = 80; i <= 50; i++) loop working out
properly. Any advice would be great. Thank you.
Sounds like a homework problem.

Here's a hint: if you want your loop to go backwards, adding to
(incrementing) the counter isn't going to work.

Here's another hint: if you want fractional values, using integers isn't
going to work.

One final hint: in a "for()" statement, the three parts have very broad
rules for usage. The first part is executed once, before the loop begins,
and may contain variable declarations; the second part must simply be some
sort of logical expression that evaluates to a boolean...it can be _any_
expression that meets that requirement; and finally, the third part can be
any statement or statements (separated by commas)...there's nothing that
says it can only be a variable combined with a post-increment operator.

With that information, I think you should be able to rewrite your loop so
that it meets your need.

Pete
Jun 27 '08 #1
1 2049
Love the hints, espectially this one *******. Thats really made my day......

;-D

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sat, 17 May 2008 16:36:17 -0700, <msnews.microsoft.comwrote:
[...]
I can't seem to get the for (int i = 80; i <= 50; i++) loop working out
properly. Any advice would be great. Thank you.
Sounds like a homework problem.

***** Here's a hint: if you want your loop to go backwards, adding to
******
(incrementing) the counter isn't going to work.

Here's another hint: if you want fractional values, using integers isn't
going to work.

One final hint: in a "for()" statement, the three parts have very broad
rules for usage. The first part is executed once, before the loop begins,
and may contain variable declarations; the second part must simply be some
sort of logical expression that evaluates to a boolean...it can be _any_
expression that meets that requirement; and finally, the third part can be
any statement or statements (separated by commas)...there's nothing that
says it can only be a variable combined with a post-increment operator.

With that information, I think you should be able to rewrite your loop so
that it meets your need.

Pete
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
1
by: Marcin Kaliciński | last post by:
template<class RanAccIt> void some_algorithm(RanAccIt begin, RanAccIt end) { // this algorithm involves calling std::lexicographical_compare // on range [begin, end), and on reverse of this range...
3
by: R. Rajesh Jeba Anbiah | last post by:
Unfortunately, I couldn't find any way to traverse the object array in reverse order. I'd thought there must be a way to do it with for..in loop, but couldn't find anything yet. Could someone...
21
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the...
13
by: Aamir Mahmood | last post by:
What could be the fastest method to reverse a string. Speed really matters for my application. Average size of string that comes to my function is around 200K - 300K. Currently i am using the...
41
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
38
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
15
by: Alex Snast | last post by:
Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i)
7
beacon
by: beacon | last post by:
Hi everybody, This may be an easy one, but I'm having a lot of trouble with it. I have a continuous form and I want to validate that the user has entered something in each of the required fields...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.