Different in execution of code Arduino / PLC

Hi,

I'm experienced in programming PLC's and starting with Arduino. Biggest difference I realized is for example FOR (for(int i=0; i <= 255; i++){}) instruction. In PLC all code is executed in once cycle, so FOR instruction increase "i" just by one and rest of the code is executed. Arduino will execute complete FOR function and then continue to execute rest of the code.

But what if I want to do some calculation and also control I/O in real time. Right now when Arduino start executing FOR function and it doesn't execute anything else, for few seconds.

I'm probably using wrong mindset, could anyone point me to some article about right way to make a program (like structure, cycle etc.)

Thanks

This is not behaviour of the Arduino but patterns of C/C++ language so you should read more about the C. The 'for' statement has conditional expression in the middle and while it is evaluated nonzero (TRUE) the code closed inside of braces will be executed.

But what if I want to do some calculation and also control I/O in real time.

Don't use a for loop. Let the loop() function do the work for you

See Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE if you need things to happen at defined intervals without affecting other code.

You've got to get used to the setup() loop() paradigm.
Using your own loop construct (say with for ) is less usual here, although there are circumstances where it is perfectly valid. It is more usual to rely on the inherent repetition in the loop() function so other statements can also be interleaved and excude pseudo simultaneously.

UKHelibob types quicker than I can.

Thanks gentleman's, thats what I'm looking for.

Instead of "for" I will use if
(i<=400){i++;}
Or I could use "while" function

Or you could just use the loop() function as previously suggested

maybe like this:

int i ; 

void setup() {
   i = 0 ;
}

void loop() {

   if ( i <= 400 ) {
      i++ ;
   } 

}