473,326 Members | 2,012 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,326 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 2038
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.