For bool loop help needed

Hi All, i'm new to Arduino, it is good to be here and learn from everyone else.

I started working on a CC1101 Transceiver module, and I have the need to send data from one transceiver to another, I found the CC1101 library in the forums, and in following the examples I came across a piece of code that don't quiet understand the meaning, I am a professional in Java, Python and Visual Studio but it is my first time dealing with arduino.

The code is the following, and I was wondering if you guys could help me translate it into simple english :slight_smile:

For (bool i = 0; i==0;){

I know is a for loop, but I don't understand why the variable i is a boolean, I just don't understand how many times the loop will iterate since the next statement is i==0.
Will this loop only iterate once through the code inside of the loop?

I'm just a little confused.

Thanks everyone in advanced for your help.

Walter

for( )

Show us the surrounding lines of code.

This sets up an infinite loop.

The for statement has 3 parts...

bool i = 0; // This initialises things when the loop starts. So effectively sets a boolean to false.

I==0; // This condition needs to remain true for the loop to continue.

The 3rd part is missing... this gets executed and the end of each loop... so nothing in this case.

The only way out of that loop, is for something to set the bool to true inside the loop.

It's not a particularly good way to do this, as it is (as proven by your post) confusing to someone reading the code.

Might be easier to understand:

while (i == false)
{
. . . 
}

@walterf25 You posted this question in the Introduction Tutorials section. That section is for posting Tutorials, not asking questions about your project. Therefore I have moved it here.

You may want to read this before you proceed:-
how to get the best out of this forum

And change i To something more meaningful (and define it too as it was declared in the for loop initially)

bool KeepCheckingForCondition = true;
while (KeepCheckingForCondition) {
  … // somewhere in this loop, set KeepCheckingForCondition = false;
}