Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/22/10 06:49
Modified:
  10/22/10 08:55

Read: times


 
#179261 - for( expression-1; expression-2; expression-3 ) [ed]
Responding to: ???'s previous message
Justin Fontes said:
I have never seen a for loop written in this manner:

for( i = 0x01; i; i <<= 1 )

It's really not that strange

i is instantiated as 0x01

No, i is not instanciated - that means, "to create an instance of"

In 'C' (unlike C++), i must already exist before it can be used; ie, it must already have been "instanciated" (although that is not really a term used by 'C').

The term is "initialised" - or, in fact, just "set to 1" would do!

the for loop never compares

A for loop always take the value of the 2nd expression as the condition on whether to exit or continue the loop: if the value of the 2nd expression is zero, the loop exits; otherwise, it continues.

Note: The above paragraph has been corrected to say "2nd" (it was initially wrong and said "3rd") - see: http://www.8052.com/forum/read/179267


There doesn't need to be a explicit comparison here!


last I checked I did not think i was a condition.

Well, it's not a condition as such - it's just a value, and the decision is based on whether that value is zero or non-aero.

The same applies in if() clauses, and anywhere else that 'C' makes a true/false decision.

eg, the common
   while( 1 ); // loop forever

or, similarly
#if 0
   // this code is disabled
   :
   :
#endif


I do not have enough eyes to see what you're doing with your i's!

Very good - I like that one!


List of 49 messages in thread
TopicAuthorDate
p89lpc936 keil programming help required.            01/01/70 00:00      
   magic code?            01/01/70 00:00      
      mov 0A5H,#0FFH            01/01/70 00:00      
   a glaring difference            01/01/70 00:00      
      a glaring difference            01/01/70 00:00      
         what happens if            01/01/70 00:00      
            what happens if            01/01/70 00:00      
               BiDir or PushPull            01/01/70 00:00      
               I leave it to you            01/01/70 00:00      
                  magic code?            01/01/70 00:00      
                  I leave it to you            01/01/70 00:00      
                     1) formatted, 2)commented, 3) correct            01/01/70 00:00      
                        1) formatted, 2)commented, 3) correct            01/01/70 00:00      
                           it is STILL two different things            01/01/70 00:00      
                              Apples and Orange Juice            01/01/70 00:00      
                                 Please focus on the problem i have            01/01/70 00:00      
                                    Software delay loop in C is a no-no            01/01/70 00:00      
                                       Software delay loop in C is a no-no            01/01/70 00:00      
                                          Reduce problem into smaller problems            01/01/70 00:00      
                                             Reduce problem into smaller problems            01/01/70 00:00      
                                             Simulator vs real hardware            01/01/70 00:00      
                                             Current limits            01/01/70 00:00      
                                             Per Westermark's previous message            01/01/70 00:00      
                                                Delay speed            01/01/70 00:00      
                                                   Elaborate            01/01/70 00:00      
                                                      tried 5 for the '51 and Keil won            01/01/70 00:00      
                                    the problem you have is ...            01/01/70 00:00      
                                       the problem you have is ...            01/01/70 00:00      
                                          do you have LEDs connected to the simulator?            01/01/70 00:00      
                                          not executing on actual hardware while simulator is fine            01/01/70 00:00      
                                    Oh So Focused            01/01/70 00:00      
   Double-post            01/01/70 00:00      
   Are you using the limited version of KEIL? the for loop....            01/01/70 00:00      
      valid C            01/01/70 00:00      
         Thats the point            01/01/70 00:00      
            nope            01/01/70 00:00      
               I wouldnt trust it            01/01/70 00:00      
                  if you do not trust it ....            01/01/70 00:00      
               And if you trust it so much why doesnt it work?            01/01/70 00:00      
                  And if you trust it so much why doesnt it work?            01/01/70 00:00      
                     trust, yes, but knowledge also required            01/01/70 00:00      
                  wait call + assumptions about two-complement, ...            01/01/70 00:00      
                     The C Standard            01/01/70 00:00      
                        who is "you"?            01/01/70 00:00      
            Yes, you can!            01/01/70 00:00      
      Quite common loop design for bit operations            01/01/70 00:00      
      for( expression-1; expression-2; expression-3 ) [ed]            01/01/70 00:00      
         erratum            01/01/70 00:00      
            Corrigendum            01/01/70 00:00      

Back to Subject List